Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Centering a

    inside a
  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #30517
    Propheis
    Member

    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!

    #67876
    cybershot
    Participant

    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.

    #67809
    Propheis
    Member

    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.

    #67810
    PeretzM
    Member

    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.

    #67829
    Jerm993
    Member

    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.

    #67705
    Propheis
    Member

    the link to the site is “Propheis.com”

    #67707
    Propheis
    Member

    *sigh* if only this was valid CSS.

    nav ul { width: just enough for the content; margin:0px auto; }

    ;)

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘CSS’ is closed to new topics and replies.