Results 1 to 2 of 2

Thread: CSS Menus

  1. #1
    Join Date
    May 2006
    Location
    England
    Posts
    218

    CSS Menus

    Hey

    I got a css menu:

    #menu {
    width:100%;
    background-color:#C80000;
    margin-bottom:3px;
    }
    ul#nav {
    margin-left:0px;
    padding-left:0px;
    padding-top:0px;
    margin-top:0px;
    list-style-type:none;
    background-color:#C80000;
    float:left;
    width:100%;
    }
    ul#nav li {
    display:inline;
    }
    ul#nav a {
    display:block;
    float:left;
    padding:6px 21px;
    text-decoration:none;
    color:#ffffff;
    background-color:#C80000;
    }
    ul#nav a:hover {
    color:#ffffff;
    background-color:#960000;
    }
    At the moment there is a gap at the end where there are not buttons. is there any way to equally spread the buttons over the alocated width so it fills all the menu bar up?

    thx
    Dave.

  2. #2
    Join Date
    Feb 2006
    Location
    Salisbury UK
    Posts
    4,332
    Change ul#nav a to
    { width:15%; display:block; float:left; padding:6px 21px; text-decoration:none; color:#ffffff; background-color:#C80000; text-align: center;}

    I tried it with five links in the menu expecting 100%/5 to be 20% each but it didn't work. I had to reduce % to 15% and I'm not sure why; probably the padding of 21px in each. Temporarily add border: 1px solid to see the spacing. The end one may appear to be not reaching the end, but that may be a combination of the padding and that text is aligned left so a larger space appears to the right. I added text-align: center to spread them out within each space.

    The principle is OK though, it spreads out the links over the menu whatever the screen resolution, except if the screen gets too small for them when the end one will flip down.
    ---------
    Changing to width:19.7% and padding:6px 0px also works for five links. 20% probably not possible because of body margins. (Decimal points can be used for percentages).
    Last edited by Wickham; 20 May 2006 at 04:48 AM.
    Code downloaded to my PC will be deleted in due course.
    WIN7; IE9, Firefox, Opera, Chrome and Safari for Windows; screen resolution usually 1366*768.
    Also IE6 on W98 with 800*600 and IE8 on Vista 1440*900.

Similar Threads

  1. CSS? (drop-down menu) problem in IE7
    By webbcity in forum Web Design, HTML Reference and CSS
    Replies: 1
    Last Post: 17 Feb 2006, 02:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •