Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3

Thread: Menu problem

  1. #1
    Member
    Join Date
    Jul 2011
    Posts
    95
    Member #
    28555
    Liked
    1 times
    I am trying to add a simple drop down menu under one of my links and am struggling with positioning and sizing.

    HTML Code:
    <div class="nav">
    <ul>
    <li><a href="<?php echo get_site_url(); ?>">Home</a></li>
    <li><a href="<?php echo get_permalink( 39 ); ?>">Retailers</a>
    <ul>
    <li><a href="">How It Works</a></li>
    <li><a href="">How You Benefit</a></li>
    <li><a href="">What You Keep</a></li>
    </ul></li>
    </ul>
    .nav ul li {display: inline; height: 50px; line-height: 50px; padding: 20px; width: 80px;}
    .nav ul li a {font-size: 12px; color: #313E49;}
    .nav ul li:hover {background: #313E49;}
    .nav ul li:hover a {color: #fff;}
    .nav ul ul {position:absolute; left:-9999px; width:150px;}
    .nav ul li:hover ul {position: absolute; left:-9999px; width: 150px;}
    .nav ul li:hover ul {left: 0; top:60px;}
    .nav ul ul li {height: 50px; background: #313E49; color: #fff; width: 150px;}
    .nav ul ul li a {height: 50px; line-height: 50px;}

    The problem I am having is that the width appears not to be working as each list item is a different width and also the positioning, I want the second level to be under "Retailers" but it is at the very left of the screen, I know this may be because I have position absolute and left 0 but if I try position relative then on hover, the links after Retailers (which I havent included in source above) all move on hover.

  2.  

  3. #2
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    You have the positioning problem nailed. You're using absolute, which is screwing you up. You could set the parent element to position:relative, and it should work. I would, however consider fixing the movement problem instead of applying a band-aid.

    For the width problem, this is why I don't use the display:inline method for nav lists. As you see here, an inline element only takes up as much space as what it contains. You can't set a height/width on it. 2 options here:
    1. Use inline-block instead.
    2. Float the li and leave them display:block.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  4. #3
    Member
    Join Date
    Jul 2011
    Posts
    95
    Member #
    28555
    Liked
    1 times
    Thanks Ronald, sorted :-)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 04:38 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com