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 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2012
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    ul inside another ul not aligning


    Hello Im making a simple Css navigation
    I can't figure out why buttons aren't positioned correctly

    Code:
    <div id="wrap">
    	<div id="menu">
    		<ul>
    			<li><a href="#1">Welcome</a></li>
    			<li><a href="#2">Nav</a>
    			<ul>
    				<li><a href="">Something</a></li>
    				<li><a href="">Another</a></li>
    				<li><a href="">Yippie</a></li>
    				<li><a href="">Yay</a></li>
    			</ul>
    			</li>
    			<li><a href="#3">Join</a></li>
    			<li><a href="#4">Relax</a></li>
    		</ul>
    	</div>
    </div>	
    
    #wrap { margin: auto; width:800px;}
    #menu { width:800px; height:50px; margin:0; padding:0; }
    #menu ul { 
    width:800px; 
    height:50px;
    list-style:none;
    }
    
    #menu ul li { 
    width:195px;
    
    float: left;
    text-align:center;
    background-color:grey;
    height:50px;
    display:block;
    position:relative;
    
    }
    
    #menu ul li ul li { 
    float: none; 
    
    }
    
    #menu ul li a {
    text-decoration:none;
        padding: 15px;
    	display:block;
    	border:1px solid white;
    }
    
    #menu ul li:hover { 
    background-color:white;
    }
    li ul {
        display: block;
        position: absolute;
    }

    Last edited by nitzanb; 11-19-2012 at 08:53 PM.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,445
    Thanks
    23
    Thanked 630 Times in 629 Posts
    Code:
    li ul {
        display: block;
        position: absolute;
    	left: -40px;       // ADD THIS
    }
    P.S. display: block; This is the default so it is not needed.

  • #3
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Good morning nitzanb,
    That's the default 40px padding on the ul that's causing that.
    Remove it with this bit highlighted in red -
    Code:
      li ul {
        display: block;
        padding: 0;
        position: absolute;
    }
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #4
    New Coder
    Join Date
    Sep 2012
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you Excavator you solved it.

    sunfighter thank you too, havnt tried it but you're kind.


    *solved


  •  

    Posting Permissions

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