- This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
Viewing 7 posts - 1 through 7 (of 7 total)
- The forum ‘CSS’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Hello,
For some reason, my brain is failing me, and I cannot center an unordered list in my nav element. :(
Here is the CSS for it, i can’t understand why this won’t work :S
nav { width:100%; height:30px; margin-bottom:20px; }
nav ul { margin:0 auto; }
What is wrong/missing, that my unordered list won’t centre?
Thanks for any help!
well, the nav ul is most likely 100% of your browser as well and because it is so wide, it can’t center. You could try putting a width on the ul or surrounding it with another wrapper div, put a width on that. Make it just wide enough to fit your nav.
I would put a width on the ul, but I want the whole ul to expand to fit it’s content, that way I wouldn’t have to change CSS every time I want to add/remove a link from the ul.
I’m not sure if this is what you’re looking for, but maybe try adding text-align:center; to your ul. This way the lis within the ul are centered. A link to the site would help.
The margin: 0 auto; trick only works if there is a defined width for the element, otherwise it can’t calculate the margin on both sides (auto) and defaults.
the link to the site is “Propheis.com”
*sigh* if only this was valid CSS.
nav ul { width: just enough for the content; margin:0px auto; }
;)