horizontal menu not centered

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mickey0
    New Member
    • Jan 2008
    • 142

    #1

    horizontal menu not centered

    Hello,
    I tried this code online but I'm not able to center it on my own page. It stays on the left. How is it possibile to do it? And even how can I put it on the right? Thanks a million.
    Code:
    <div id="menu01o">
     <ul>
      <li><a href="#">Link 1</a></li>
      <li><a href="#">Link 2</a></li>
      <li><a href="#">Link 3</a></li>
      <li><a href="#">Link 4</a></li>
      <li><a href="#">Link 5</a></li>
     </ul>
    </div>
    Code:
    #menu01o {
    width: 100%;
    font: 80% Arial, Helvetica, sans-serif; 
    }
    #menu01o ul{
    margin: 0;
    padding-left: 0;
    list-style: none;
    }
    #menu01o li{
    font-size: 1.1em;
    display: inline;
    margin: 0;
    padding: 0;
    }
    #menu01o a:link, #menu01o a:visited{
    float: left;
    background: #800000;
    color: #fff;
    margin: 0em;
    padding: 0.3em 1.5em 0.3em 1.5em;
    text-decoration: none;
    border: 1px solid #000;
    }
    #menu01o a:hover, #menu01o a:focus, #menu01o a:active{
    color: #000;
    background: #FFFF00;
    }
  • aelisenko
    New Member
    • Oct 2011
    • 7

    #2
    If I understood correctly, you want to center the horizontal menu within the parent div (#menu01o). adding text-align:center; should do it.

    Code:
    #menu01o {
    text-align:center;
    width: 100%;
    font: 80% Arial, Helvetica, sans-serif; 
    }
    quick question.. is there a reason you're using a list? having just the anchor tags would give the same result with less html and less css. just food for thought.

    Comment

    • mickey0
      New Member
      • Jan 2008
      • 142

      #3
      Apparently it doens't work; but I take "float:left " off, it works.
      However, in this way there is space between thes "boxes" and they are not stuck (and I want them stuck):
      Code:
      #menu01o a:link, #menu01o a:visited{
         /* float: left; */
         ..............
      }
      No reason for using lists; I'll try just the <a>

      Comment

      • aelisenko
        New Member
        • Oct 2011
        • 7

        #4
        I suggest just using:

        Code:
        <div id="menu01o">
          <a href="#">Link 1</a>
          <a href="#">Link 2</a>
          <a href="#">Link 3</a>
          <a href="#">Link 4</a>
          <a href="#">Link 5</a>
        </div>
        and then changing css to:

        Code:
            #menu01o {
              text-align:center;
              width: 100%;
              font: 80% Arial, Helvetica, sans-serif; 
            }
            #menu01o a:link, #menu01o a:visited{
              background: #800000;
              color: #fff;
              margin: 0em;
              padding: 0.3em 1.5em 0.3em 1.5em;
              text-decoration: none;
              border: 1px solid #000;
            }
            #menu01o a:hover, #menu01o a:focus, #menu01o a:active{
              color: #000;
              background: #FFFF00;
            }

        Comment

        • mickey0
          New Member
          • Jan 2008
          • 142

          #5
          The boxes are still spaced but putting "margin: -0.3em;" within #menu01o a:link, #menu01o a:visited{ .. } instead "margin: 0px", it seems working...Still a problem: the top of this "row" of boxes overlaps with the bottom of a table....

          Comment

          Working...