Problem with reversal of menu when floated to the right in CSS - css-float

I've got a div that is set to 100% and inside that another div which is centred and set to 883px.
The navigation is a list but if I apply the float:right element to this element it reversed the order of the list. Sure I could change the order in the code but there must be a better way?
<div id="navigation"><!-- START NAVIGATION -->
<ul class="navigation">
<li>home</li>
<li><img src="images/navline.png" align="right">portfolio</li>
<li>blog</li>
<li>get in touch</li>
</ul>
</div>
<div id="border"></div><!-- END NAVIGATION -->
<div style="clear:both"></div>
And the CSS...
#navigation {
width:100%;
background-color:#383a3c;
height:43px;
}
#navigation ul {
width:883px;
margin:0px auto;
}
ul.navigation {
font-family:'ChunkFiveRegular', Arial, sans-serif;
font-size:18px;
}
#navigation li a {
display:block;
margin:13px 0px 0px 0px;
text-decoration:none;
color:#8cd8db;
float:right;
}
Can anyone help show me the error of my ways?

Floating to the right reverses the elements. This is the expected behavior.
If you want the menu aligned to the right, then you need to make ul element floating to the right but the li elements inside, must have a float left.
#navigation {
width:100%;
background-color:#383a3c;
height:43px;
}
#navigation ul {
width:883px;
margin:0px auto;
}
ul.navigation {
font-family:'ChunkFiveRegular', Arial, sans-serif;
font-size:18px;
float: right;
}
#navigation li {
float: left;
padding: 0px 10px;
}
#navigation li a {
display:block;
margin:13px 0px 0px 0px;
text-decoration:none;
color:#8cd8db;
}
In this case, the menu still doesn't appear aligned to the right because you specified width:883px; to the ul element. If you want it aligned to the right then simply remove this width.

Related

ul does not display bullets

One of my UL is not displaying correctly. It is both displaying things inline and also the bullets do not show.
I know that this issue is isolated strictly to my divs that are used with my tabbed interface. I'm also assuming this is due to the hierarchy above. (The .tabs li says to display things 'inline'.) If I delete that, obviously the tab interface is screwed. How can I keep my divs displaying horizontally, and have the lists inside of the div box display in a block?
Thanks!
CSS
.basics ul {font-family:terminal;
font-size:9px;
text-transform:uppercase;
color:gray;
padding:0px;
display:block;
}
li.basics { list-style-image: url('/bullet.png');
}
ul b {font-family: terminal;
font-size: 8px;
text-transform:uppercase;
color:#fff3a2;
font-weight:lighter;
}
div.tabs {
padding:15px;
width:760px;
background:#000;
color:#fff;
border-radius: 0em 4em 1em;
-moz-border-radius: 10px;
margin-left:3px;
height:200px;
overflow: auto;
}
ul.tabs {
padding:0;
margin:0;
margin-top:10px;
margin-left:3px;
}
.tabs li {
list-style:none;
display:inline;
}
and the html code:
<ul class='tabs'>
<li><a href='#tab1'>BASICS</a></li>
<li><a href='#tab2'>BIOGRAPHY</a></li>
<li><a href='#tab3'>RANDOM</a></li>
<li><a href='#tab4'>NPCs</a></li>
</ul>
<div id="tab1" class="tabs">
<ul class="basics">
<li><b>Full Name:</b>
<li><b>DOB:</b> 27 May 1985; 28 YRS </li>
<li><b>Birthplace:</b>Olinda, Brasil</li>
<li><b>Nationality:</b>Brazilian, French, & American</li>
</ul>
If I'm understanding your question correctly, you want the top to be horizontal, and the lower one to be vertical. I just changed your rule from .tabs li to ul.tabs li
http://jsfiddle.net/itsmikem/3RwMn/
Let me know if that's your issue.

css trouble with centering a horizontal unordered list

I have had trouble centering the unordered list I am using for my navigation. I have looked at other advice and tried to fix it so now my code is a hot mess. I cannot figure out for the life of me what is going wrong. All the solutions I have tried still do not center the list in the window. adding the overflow:visable stretch it out but not 100% and it does not expand when the window grows.
#navbar {
position: fixed;
top:-17px;
margin-bottom: 10px;
font-family:Verdana, Geneva, sans-serif;
margin: 0;
padding: 0;
}
#navbar ul > li {
display: inline-block;
float: none;
color:white;
font-size: 14px;
margin-right: 35px;
margin-left: 35px;
padding: .2em 1em;
overflow:visible;
}
Is this what you are looking for?
http://jsfiddle.net/talymo/6FGbw/
#navbar {
position:fixed;
list-style:none;
margin:0;
padding:0;
width:100%;
text-align:center;
}
#navbar li{
padding:10px;
display:inline-block;
}
<ul id="navbar">
<li>Thing 1</li>
<li>Thing 2</li>
<li>Thing 3</li>
</ul>
what if you add this to your code:
text-align: center
One thing you can try is to put the list inside a div and add the style text-align:center; to the div.
Afterwards just remove the position:fixed; style from #navbar.
or you could wrap the list in <center> </center> tags.
Hope this helps :)
Try:
#navbar ul {
text-align: center;
}
JSFiddle: http://jsfiddle.net/zgwxP/
Assuming your navbar has some set width you can use text-align:center on your ul
jsFiddle
/* Give the navbar a width */
#navbar {
left:0;
right:0;
}
#navbar ul {
padding:0;
text-align:center;
}

How to center a ul within a div menu

I'm trying to center a ul within a div menu. I've looked at other menu's and tried every combination I can think of, yet I still can't get it.
Here's the code:
#cssmenu ul{
margin:0 auto;
padding:0;
list-style-type:none;
width:100%;
position:relative;
display:block;
height:38px;
font-size:14px;
background:#f9f8f8;
border-top: 1px solid #e5e5e5;
border-bottom: 1px solid #e5e5e5;
font-family:Arial,Helvetica,sans-serif;
}
#cssmenu li{
display:block;
float:left;
margin:0;
pading:0;
}
#cssmenu li a{
display:block;
float:left;
color:#333333;
text-decoration:none;
padding:12px 20px 0 20px;
height:24px;
height:38px;
}
#cssmenu li a:hover{
text-decoration:underline;
}
<div id="cssmenu">
<ul>
<li>Home</li>
<li>About</li>
<li>The Program</li>
<li>Blog</li>
<li>Support</li>
<li>Members Login</li>
</ul>
</div>
Any help would be greatly appreciated.
Thanks!
Mike
You have to remove the width: 100% from the ul first. You can't really center something that is the same size as the container :). After removing that, you could make the list inline-block, so it takes up the width of its children, and then using a simple text-align on the div.
#cssmenu {
text-align: center;
}
#cssmenu ul{
display: inline-block;
}
Of course you will have to move some of your styles from the list to the div, because the list is not full width anymore.
jsFiddle Demo

css inline list margins

I have an inline list that I am trying to get to "fill" the entire width of it's div.
If I use a margin-right on the list the last element will either not reach the end of the div (because it had the right margin) or the right margin will force it to go to the next row as it exceeds the width of the div.
Here is an excample of what I am describing.
http://i.imgur.com/9CJx7.png
my html:
<div id="footerstick" style="background:url(site_files/bg_shears.png) repeat-x; ">
<div id="footer_wrap">
<div id="footer_top_shelf">
<ul>
<li>Contact Us</li>
<li>FAQ</li>
<li>About Us</li>
<li>Distribution</li>
</ul>
</div>
</div>
</div>
my css:
#footerstick {
position: relative;
margin-top: -230px; /* negative value of footer height */
height: 230px;
clear:both;
}
#footer_wrap {width:980px; margin:auto;}
#footer_top_shelf {height:70px; overflow:hidden; }
#footer_top_shelf ul li {display:inline; list-style:none; color:#c7c7c7; font-size:30px; margin-right:85px; line-height:75px; text-transform:uppercase; font-family:myriad pro; }
Write like this:
#footer_top_shelf ul li + li{
margin-left:85px;
}
Try below css - after seeing your image and as per your requirement, if i am getting your problem correct the this updated css should help you.
#footerstick {
position: relative;
margin-top: -230px; /* negative value of footer height */
height: 230px;
clear:both;
}
#footer_wrap {width:980px; margin:auto;}
#footer_top_shelf {height:70px; overflow:hidden;}
#footer_top_shelf ul
{
margin:0;
padding:0;
text-align:center;
}
#footer_top_shelf ul li {
display:inline;
list-style:none;
color:#c7c7c7;
font-size:30px;
margin:0px 40px;
line-height:75px;
text-transform:uppercase;
font-family:myriad pro;
}
Note: Can you show your real time code, so we can identify easily how your code working and where you are facing problem.

float and display affection on width and height

What is the effect of inline and block and inline-block and floating to width and height?
For example take look at below css menu :
ul
{
list-style-type:none;border-style:solid;border-width:1px;border-color:Blue;
padding:0px;
display:inline-block;
float:left;
}
ul li{display:inline;}
ul li a
{
/*display:inline-block;
float:left;*/
display:inline-block;
float:left;
background-color:rgb(100,170,110);
color:Yellow;
text-decoration:none;
height:30px;
padding-left:20px;
padding-top:5px;
padding-right:20px;
}
ul li a:hover{background-color:Yellow;color:Red;}
I have corrected that for both IE and Firefox with adding below codes for ul:
display:inline-block;
float:left;
Is it true that for a inline tag the height=0?
Is it true for the left floated tag , it width is the maximum widths of it's children ?
Why block elements (such as menu items) will have some margins with their next items?
You'll get some goofy stuff with inline-block with IE. You might have better luck setting tha a's to block and float the li's. Try the code below
HTML
<nav>
<ul>
<li>Home
<li>About
<li>Contact
</ul>
</nav>
CSS
ul { margin: 0; padding: 0; }
li { float: left; }
a { display: block; padding: 5px; margin: 0 5px; }

Resources