float: left
will left-align your list items. You can achieve a similar effect to floating by using display: inline-block
instead. Then put text-align: center
on your .menu2
rather than align-items
.
.menu2 {
list-style: none;
text-align: center;
margin: 0;
padding: 0;
}
.menu2 li {
display: inline-block;
width: 80px;
padding: 1px;
}
.menu2 > li a {
display: block;
font-size: 0.8em;
padding: 3px;
text-decoration: none;
text-align: center;
color: #333333;
border: 1px solid #d6d6d6;
transition: all ease .5s;
}
.menu2:hover > li a {
opacity: .5;
transition: all ease .5s;
}
.menu2 > li:hover a {
opacity: 1;
color: #D2383C;
border-color: #D2383C;
}
<ul class="menu2">
<li><a href="">2014</a></li>
<li><a href="">2013</a></li>
<li><a href="">2012</a></li>
</ul>
Note that a caveat of display: inline-block
is that whitespace between the items will produce visual space between the menu items (notice the wider gap between the items in my code snippet versus the OP's). There are several possible solutions to this:
(1) Placing all li
s on the same line with no whitespace between </li><li>
(but this doesn't look too good in the source
<ul class="menu2">
<li><a href="">2014</a></li><li><a href="">2013</a></li><li><a href="">2012</a></li>
</ul>
(2) Achieving the equivalent effect by putting the whitespace in a comment (which also looks weird), e.g.
<ul class="menu2">
<li><a href="">2014</a></li><!--
--><li><a href="">2013</a></li><!--
--><li><a href="">2012</a></li>
</ul>
(3) Specifying font-size: 0;
on .menu2
and overriding the font-size
on the .menu2 li
.