Reputation: 937
I've been trying to get the text to align center, but I can't get it to work. Also the text starts to creep to the right inside its box after every menu item. I started to get annoyed and threw a bunch of text-align: center;
all over the place, but I just don't know what else to do here.
I have a bar that underlines whatever menu you are hovering over and a different colored bar for the active item.
HTML:
<div class="menu">
<div id="cssmenu">
<ul>
<li><a href="index.html"><span>Home</span></a></li>
<li><a href="about.html"><span>About</span></a></li>
<li class="active"><a href="news.html"><span>News</span></a></li>
<li><a href="gallery.html"><span>Gallery</span></a></li>
<li class="last"><a href="contact.html"><span>Contact</span></a></li>
</ul>
</div>
</div>
CSS:
/*-- Menu Logo --*/
.logo {
float: left;
/*background: #DE5491;*/
padding: 23px 20px;
width: 406px;
height: 80px;
vertical-align: central;
}
.menu {
float: right;
width: 53%;
}
/*--menu--*/
#cssmenu li,
#cssmenu span,
#cssmenu a {
/*margin: 0;*/
padding: 0;
position: relative;
text-transform: uppercase;
text-align: center;
}
#cssmenu {
padding-top: 40px;
}
#cssmenu:after,
#cssmenu ul:after {
content: '';
display: block;
clear: both;
}
#cssmenu a {
color: #000;
display: inline-block;
line-height: 49px;
padding: 0 51px;
text-decoration: none;
font-weight: normal;
font-size: 1.5em;
font-family: 'bebas_neueregular';
text-align: center;
}
#cssmenu ul {
/*list-style: none;*/
}
#cssmenu > ul {
/*float: left;*/
text-align: center;
}
#cssmenu > ul > li {
float: left;
/*display:block;*/
text-align: center;
/*width: 24.9999%;*/
width: 19.9999%;
}
#cssmenu > ul > li > a {
color: #000;
}
#cssmenu > ul > li:hover:after {
content: '';
display: block;
padding-top: 46px;
border-bottom: 10px solid #003; /*-- Menu Bar Hover Color --*/
-webkit-transition: .2s all linear;
-moz-transition: .2s all linear;
-o-transition: .2s all linear;
transition: .2s all linear;
}
#cssmenu > ul > li.active:after {
content: '';
display: block;
padding-top: 46px;
border-bottom: 10px solid #252425; /*-- Menu Bar Color --*/
-webkit-transition: .2s all linear;
-moz-transition: .2s all linear;
-o-transition: .2s all linear;
transition: .2s all linear;
}
Upvotes: 0
Views: 88
Reputation: 116
Try this...Took of the width of #css > ul > li, added a fixed width to #cssmenu ul and margin: 0px auto to #cssmenu li, #cssmenu span, #cssmenu a
/*--menu--*/
#cssmenu li,
#cssmenu span,
#cssmenu a {
margin: 0px auto;
padding: 0;
position: relative;
text-transform: uppercase;
text-align:center;
list-style:none;
}
#cssmenu ul {
width: 960px;
}
Upvotes: 0
Reputation: 4413
/*-- Menu Logo --*/
.logo {
float: left;
/*background: #DE5491;*/
padding: 23px 20px;
width: 406px;
height: 80px;
vertical-align: central;
}
.menu {
float: right;
width: 53%;
}
/*--menu--*/
#cssmenu li,
#cssmenu span,
#cssmenu a {
/*margin: 0;*/
padding: 0;
position: relative;
text-transform: uppercase;
text-align: center;
}
#cssmenu {
padding-top: 40px;
}
#cssmenu:after,
#cssmenu ul:after {
content: '';
display: block;
clear: both;
}
#cssmenu a {
color: #000;
display: inline-block;
line-height: 49px;
/*padding: 0 51px; */
text-decoration: none;
font-weight: normal;
font-size: 1.5em;
font-family: 'bebas_neueregular';
text-align: center;
}
#cssmenu ul {
list-style: none;
}
#cssmenu > ul {
/*float: left;*/
text-align: center;
}
#cssmenu > ul > li {
float: left;
/*display:block;*/
text-align: center;
/*width: 24.9999%;*/
width: 19.9999%;
}
#cssmenu > ul > li > a {
color: #000;
}
#cssmenu > ul > li:hover:after {
content: '';
display: block;
padding-top: 46px;
border-bottom: 10px solid #003;
/*-- Menu Bar Hover Color --*/
-webkit-transition: .2s all linear;
-moz-transition: .2s all linear;
-o-transition: .2s all linear;
transition: .2s all linear;
}
#cssmenu > ul > li.active:after {
content: '';
display: block;
padding-top: 46px;
border-bottom: 10px solid #252425;
/*-- Menu Bar Color --*/
-webkit-transition: .2s all linear;
-moz-transition: .2s all linear;
-o-transition: .2s all linear;
transition: .2s all linear;
}
<div class="menu">
<div id="cssmenu">
<ul>
<li><a href="index.html"><span>Home</span></a>
</li>
<li><a href="about.html"><span>About</span></a>
</li>
<li class="active"><a href="news.html"><span>News</span></a>
</li>
<li><a href="gallery.html"><span>Gallery</span></a>
</li>
<li class="last"><a href="contact.html"><span>Contact</span></a>
</li>
</ul>
</div>
</div>
Upvotes: 0
Reputation: 8621
It's happening because of this rule:
#cssmenu a {
color: #000;
display: inline-block;
line-height: 49px;
text-decoration: none;
font-weight: normal;
font-size:1.5em;
font-family: 'bebas_neueregular';
text-align:center;
}
Need to remove padding: 0 51px;
because it causes your anchor to be too wide for it's container.
Upvotes: 1