WordPress.org

Forums

Center nav-area (3 posts)

  1. makta112
    Member
    Posted 2 years ago #

    Hello

    I'm trying to place my site's nav-link in the center of the site. But I'm unable to do so.

    I've tried with theese and many more without luck.

    #access ul
    {margin-left: auto;
    margin-right:auto;
    }
    
    #access ul
    {text-align:center;
    }

    Help, please.

  2. linux4me2
    Member
    Posted 2 years ago #

    You'll need to provide a link to your site if you want to get some specific help with this so people can at least see what kind of HTML/CSS framework you're dealing with.

    Ordinarily, you'd use the margin-left and margin-right set to auto as you did in the first example, but not for the ul. You'd do it with a set of divs so that the centered element has an element of greater width to center in:

    <div id="outer-element">
      <div id="access">
        <ul>
         ...
        </ul>
      </div>
    </div>

    And your CSS would be:

    #outer-element {
      width: 100%;
    }
    
    #access {
      margin-left: auto;
      margin-right: auto;
    }

    Then, as long as #outer-element is set to some width larger than the width of the content of the "access" div (it doesn't have to be 100%, but that ought to work), your access div should be centered.

  3. makta112
    Member
    Posted 2 years ago #

    Thank you! I've fixed it now :)

Topic Closed

This topic has been closed to new replies.

About this Topic