I have this html structure
<div class="top_menu">
<ul>
<li class="left"><a href="" class="family-filter">asdas</a></li>
<li class="welcome">Welcome <span class="username">Guest</span></li>
<li class="right"><a href="#">Login</a></li>
</ul>
</div>
and this css code:
.top_menu {
padding: 20px; background-color: #fff;
-webkit-border-bottom-right-radius: 5px;
-webkit-border-bottom-left-radius: 5px;
-moz-border-radius-bottomright: 5px;
-moz-border-radius-bottomleft: 5px;
border-bottom-right-radius: 5px;
border-bottom-left-radius: 5px;
}
.top_menu ul { margin: 0; padding: 0; line-height: 0; }
.top_menu ul li { display: inline; margin: 0; padding: 0; border: 1px solid red; }
.top_menu ul .welcome { text-align:center; }
.top_menu ul li a { font-size: 14px; }
I am trying to align .welcome to middle of .top_menu > ul. I’ve tried the above and this:
.center {
margin-left: auto;
margin-right: auto;
display: block;
clear: both;
}
but no success, any ideas? http://jsfiddle.net/U2mfK/
You are defining
.welcomebefore you are defining the global styles for theli. This will mean any styles in the.top_menu ul liwill override the styles in the .welcome (display:block;). Put it below like this:UPDATE
By positioning the outside
litags absolutely, you are able to prevent them from pushing the centerlioff center.Like this (I have only included the additional styles for clarity):
Alternatively, you could leave the
.leftand.rightas they are with their floats, and just position the center element absolutely like this:If you use the above method, make sure
margin-leftis half the width. You MUST specify a width for this method. If you just make it larger than content, it will center the content because of thetext-align: centerso this should not be a problem