I don't know why the first answer is the best one, I tried it and not working in fact, as @kalys.osmonov said, you can give text-align:center
to header
, but you have to make ul
as inline-block
rather than inline
, and also you have to notice that text-align
can be inherited which is not good to some degree, so the better way (not working below IE 9) is using margin
and transform
. Just remove float right
and margin;0 auto
from ul
, like below:
#header ul {
/* float: right; */
/* margin: 0 auto; */
display: inline-block;
margin-left: 50%; /* From parent width */
transform: translateX(-50%); /* use self width which can be unknown */
-ms-transform: translateX(-50%); /* For IE9 */
}
This way can fix the problem that making dynamic width of ul
center if you don't care IE8 etc.