Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    May 2007
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changing width of individual nav menu items

    I'm making a horizontal nav bar, and I'd like to have everything spaced appropriately. The thing is, when I set the li width to a certain value, all of my items are the same width. I have some list items that have longer names (i.e. "Before You Come") and some short ones (i.e. "FAQ") and with the li width set at one value, "Before You Come" is crowded down to the next line, and "FAQ" has tons of space to the left and right... Is there a way to set the width of the list items individually? Thanks.

    Robin

    P.S. My CSS looks like this:

    ul {
    padding: 0;
    margin: 0;
    list-style: none;
    position:absolute;
    left:5px;
    top:40px;
    text-transform:uppercase;
    }
    li {
    float: left;
    position: relative;
    width: 90px;
    text-align:center;
    }
    li ul {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    }
    li > ul {
    top: auto;
    left: auto;
    }
    li:hover ul { display: block; clear:left; }

  • #2
    Senior Coder
    Join Date
    Nov 2003
    Location
    Minneapolis, MN
    Posts
    2,879
    Thanks
    2
    Thanked 65 Times in 56 Posts
    You could add an individual id or class to each item list, like so:
    Code:
    <li id="nav_one"><a href="#">page one</a></li>
    <li id="nav_two"><a href="#">page two</a></li>
    <li id="nav_three"><a href="#">page three</a></li>
    But it might be easier just to let the list item width fit to each element and add a little padding to open it up a bit:
    Code:
    li {
    	float: left;
    	position: relative;
    	width: auto;
    	text-align:center;
    	padding: 0 1em;
    }
    Hope this helps…


  •  

    Posting Permissions

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