I have a navigation bar with 3 sections:
A logo
A search bar
A couple of menu options grouped together
I want it to look something like this where the logo is aligned left, the search bar has a left padding, and the grouped links are on the right:
If I try to float the group to the right, they don't vertically align to the middle.
<nav>
<a class='logo-link' href="#">Example</a>
<div class="search">
<form accept-charset="UTF-8" action="/search" method="get">
<div style="margin:0;padding:0;display:inline"></div>
<input class="main_search" type="text" />
<input class="inline_search" type="submit" value="Search" />
</form>
</div>
<div>
<div class="anchorLink">
Blog
</div>
<div class="anchorLink">
Login
</div>
<div class="anchorLink">
Register
</div>
</div>
</nav>
I've attached a fiddle of an example.
You could either use
text-align:justify; + display:inline-block; DEMO, you can then use : vertical-align:middle; to align your element to each other's middle DEMO bis
or
display:flex; + justify-content:space:between; DEMO2 You can then use margin:auto; to center on both axis DEMO3
You can use display properties, Try display:inline-block instead float and Set .search class style like this:
CSS
.search {
margin: 0 auto;
max-width: 90%;
padding-top: 0;
display: inline-block;
padding-left: 10em; /* Reduce padding
font-size: 0.75em;
}
Added CSS class
.nav--list{
display:inline-block;
}
Fiddle Example
Efficient way to do this:
Html:
<div id="header">
<ul>
<li><div>logo area</div></li>
<li><div>search area</div></li>
<li><div>other area</div></li>
</ul>
</div>
CSS:
#header ul li{
list-style:none;
display: inline;
padding-left:20%;
}
Note:
Different "display" option would give you different decoration of your elements. Here, display:inline would make the display vertical.
Check the W3schools lessons here for further understanding: http://www.w3schools.com/css/css_display_visibility.asp
If you want to align your anchor-links to the right of your layout, you should
Align the logo and the search left
Align the option-links right
By the way: I suggest to use an unordered list instead of several divs for your links
HTML
<nav>
<div class="logo">
<a class="logo-link" href="#">Example</a>
</div>
<div class="search">
<form accept-charset="UTF-8" action="/search" method="get">
<input class="main_search" type="text" />
<input class="inline_search" type="submit" value="Search" />
</form>
</div>
<ul class="anchorLinks">
<li>Blog</li>
<li>Login</li>
<li>Register</li>
</ul>
</nav>
CSS
nav {
background-color:#EEE;
height:25px;
padding:10px;
}
.logo {
float:left;
padding-right:20px;
}
.search {
float:left;
}
ul.anchorLinks {
float:right;
margin:0;
padding:0;
list-style-type:none;
}
ul.anchorLinks li {
float:left;
padding:0px 5px;
}
See jsfiddle here
Related
I'm experiencing some strange behavior with OL numbering in Chrome, here's my markup:
<ol>
<li>
<div class="block left">
<span class="block">Main Title<span class="alert">!</span></span>
<input type='text' name='title-1' />
</div>
<div class="block left">
<span class="block">Subtitle<span class="alert">!</span></span>
<input type='text' name='title-2' />
</div>
<div class="block left">
<span class="block">Add Image<span class="alert">!</span></span>
<input type='file' name='image' size='30' />
</div>
</li>
<ol>
The classes used are:
.block { display:block; }
.left { float:left; }
.alert { color:red; }
The problem I'm having is that I need the number of my OL to appear to the LEFT of the LI's contents, but Chrome seems to attribute some kind of float property to the numbers, making it appear on the right.
Can anyone provide any assistance on this matter? Thanks in advance.
ol li { margin-left: 60px; list-style-type: decimal; }
will make the numbers visible.
Wrapping the tags inside li-elements with <div class="wrap"> and apply this css to it:
.wrap { display: inline-block; position: relative; top: 12px; }
will fix your problem --> http://jsfiddle.net/GpfYk/2/
position: relative; top: 12px; makes the position nicer.
The problem is that you have a span with a class of "block" inside the li, and both are being floated. If you remove the class of block from the span, it should fix the issue.
Or, if you wish to keep the elements inline, try setting them to display: inline-block and remove the "left" class to float them as in this example: http://jsfiddle.net/jglovier/zshPr/
I have a wrapper called #sub-menu and which is displayed in yellow in the here below cssdesk file. I set its height at auto but unfortunately it is not wrapping all its content properly. This issue is driving me crazy. Hope someone can help. Thank you in advance for your replies. Cheers. Marc.
http://cssdesk.com/AVpjR
Add overflow:auto; to your #sub-menu
See: http://cssdesk.com/qBUdf
The floating elements are what disrupts the height. You need to add a new div that will clear all floating elements for the height of the parent container to fill the full length.
HTML:
<div id="sub-menu">
<div id="form-loc">
<a id="appliquer-loc" class="button white">filtrer</a>
<div id="saisi-loc">
<input id="input-loc" type="text"/>
<a id="valider-loc" class="button white">valider</a>
<a id="supprimer-loc" class="button white">supprimer</a>
<span id="msg-loc">Valeur saisie incorrecte</span>
</div>
</div>
<div id="proposition-loc">
<a id="proposer-loc" class="button white">+ Proposer une sortie</a>
</div>
<div class="clear"></div>
</div>
CSS:
#sub-menu{
width:960px;
height:auto;
margin-left:auto;
margin-right:auto;
background-color:yellow;
}
#form-loc{
width:800px;
height:auto;
float:left;
position:relative;
background-color:rgba(1,1,1,0.2);}
#saisi-loc{
background-color:rgba(123,123,123,0.2);
width:auto;}
#input-loc{
width:300px;
height:25px;
border:1px solid gray;}
#msg-loc{
font-size:14px;
padding:0 10px;
font-weight:bold;
background-color:pink;}
#proposition-loc{
text-align:right;}
.clear {
clear: both;
}
I have this code: http://jsfiddle.net/bUPWS/1/ but #div2 overflows #div1. How to bring the overflowed inputs next to the other ones?
<div id="div1">
<div id="div2">
<form>
<input/><br/><input/><br/><input/><br/><input/><br/><input/><br/><input/><br/><input/><br/><input/><br/><input/><br/><input/><br/>
</form>
</div>
</div>
#div1 {
width:400px;
height:100px;
border:1px solid red;
}
seeing your code i can say you are using <br /> tag so there is no possible way to bring your inputs next to each other. just remove each <br/> all your inputs will align properly.
additionally you can use min-height for your parent div div1
#div1 {
width:400px;
min-height:100px;
border:1px solid red;
}
#div2 input {display:inline; }
if your inputs increases more than the limit of 100px height your parent div will adjust the height with respect to the inputs inside your div2 block
EDIT: However to explain my comment below i have updated your fiddle example you can check how we can achieve it using <ul> <li></li></ul> tags
Fiddle example
Code if here!
HTML
<div id="div1">
<div id="div2">
<form>
<ul>
<li><input/></li>
<li><input/></li>
<li><input/></li>
<li><input/></li>
<li><input/></li>
</ul>
<ul>
<li><input/></li>
<li><input/></li>
<li><input/></li>
<li><input/></li>
<li><input/></li>
</ul>
</form>
</div>
</div>
CSS
#div1 {
width:800px;
min-height:100px;
border:1px solid red;
}
*{padding:0; margin:0}
#div2 ul{float:left; padding-left:10px; }
I'm not sure if this is what you looking for but you can set overflow:auto for div 1 and set float:left, for inputs. fiddle: http://jsfiddle.net/bUPWS/28/
Try using fieldset instad of div.
see: http://www.w3schools.com/tags/tag_fieldset.asp
I have 3 divs placed side by side in my application , and after the divs , I have kept a submit button.
This is how the Submit button looks if I select 'today' in date options :
but if I choose specific dates , this is what happens :
This is how the code looks like :
<div class="filters clearfix" style="float:left" id="sel_filters">
<div class="fields">
<div class="10">
<!-- this is for the date option . it contains a label and select element-->
</div>
<div>
<!-- label for start date and an input box -->
</div>
<div>
<!-- label for end date and an input box -->
</div>
<div>
<!-- label for adnetwork options " " and the select element -->
</div>
<input id="startdate_hidden" type="hidden" style="display:none;" value="" name="data[Fam][startdate_hidden]">
<input id="enddate_hidden" type="hidden" style="display:none;" value="" name="data[Fam][enddate_hidden]">
<input id="submit" class="stdButton" type="submit" onclick="return updateAddetailsNetworkWiseReport();" value="Submit" name="submit">
</div>
</div>
Now the styles :
.clearfix:after
{
clear: both;
content: ".";
display: block;
height: 0;
visibility: hidden;
}
div#sel_filters
{
margin-left: 10px;
width: 754px;
}
div.filters div.fields
{
background: url("/img/bg_summary.gif") no-repeat scroll right bottom #FFFFFF;
height: 38px;
padding-right: 10px;
}
div#sel_filters div.fields div.l0
{
margin-left: 0;
}
I added style="float:left" to the outermost div , but this problem persists . What's the exact solution would be?
To me it looks like on the bottom image two images are appearing next to the date boxes and this is causing the elements to be to wide for the containing div.
Try resizing some of the elements to make them smaller by 20-30px or; make the containing divisions width bigger, this should hopefully work.
instead float you can use display:inline-block for this with white-space property. Like this:
CSS:
.parent{
white-space:nowrap;
}
.child{
background:red;
margin:10px;
width:150px;
height:100px;
white-space:normal;
display:inline-block;
*display:inline /*IE7*/
*zoom:1;
}
HTML
<div class="parent">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>
http://jsfiddle.net/amhWX/
I have a field_wrapper class div which contains the 3 sub divs field_label, field_input and field_error
I need to put the field_label, field_input side by side and field_error below the first two.
Please see below css code to know how i achieved this, My problem is Its is not working in IE7. clear both applied to the field_error is not working.
Even after googling for a long time i can't find a proper method to fix this without adding the HTML mark-up. Please advice css tip or any other method to avoid extra markup code
.field_wrapper
{
clear:both;
}
.field_label
{
float:left;
width:40%;
}
.field_input
{
float:left;
width:40%;
}
.field_error
{
clear: both;
color:#FF0000;
float: right;
text-align:left;
width: 60%;
}
<form method="post" action="http://localhost/locations/add">
<div class="field_wrapper">
<div class="field_label">
<label for="location_add_name">Name</label>
</div>
<div class="field_input">
<input type="text" id="location_add_name" value="" name="name">
</div>
<div class="field_error">
<p>The Name field is required.</p>
</div>
</div>
<div class="field_wrapper">
<div class="field_label">
Address
</div>
<div class="field_input">
<textarea id="location_add_address" rows="12" cols="90" name="address"></textarea>
</div>
<div class="field_error">
</div>
</div>
<div class="form_submit">
<input type="submit" value="Add" name="submit">
</div>
</form>
If you do not want to remove the float left. You can use this wrapper code
.field_wrapper { display: inline-block; }
.field_wrapper:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
* html .field_wrapper { height: 1%; }
.field_wrapper{ display: block; }
It works for me every time (IE6 as well)
Update:
I looked at this again, and changed the markup a bit, also made it valid xhtml.
Just put the class on the P tag, you dont need an extra div.
.field_wrapper
{
clear:both;
}
.field_label
{
float:left;
width:40%;
}
.field_input
{
float:left;
width:40%;
}
.field_error
{
clear: both;
color:#f00;
width: 60%;
}
<form method="post" action="http://localhost/locations/add">
<div class="field_wrapper">
<div class="field_label">
<label for="location_add_name">Name</label>
</div>
<div class="field_input">
<input type="text" id="location_add_name" value="" name="name" />
<p class="field_error">The Name field is required.</p>
</div>
</div>
<div class="field_wrapper">
<div class="field_label">Address</div>
<div class="field_input">
<textarea id="location_add_address" rows="12" cols="90" name="address"></textarea>
</div>
</div>
<div class="form_submit">
<input type="submit" value="Add" name="submit" />
</div>
</form>
Remove float:right from 'field_error'
let me tell you one thing first. if you having floating content in a container the container never contain it untill and unless you set the container overflow property to hidden or also make it float you. like
.field_wrapper
{
clear:both;
overflow:hidden;
}
Now it contain all floating element. Now for your error div as you are floating you elements to left, so make clear:left only and it will work.
Thanks