SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2011
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting width from parent element

    Hello, I'm sitting here creating a site with a menu using li, etc I have

    HTML Code:
    <ul>
    	<li><a href="#">Home</a></li>
    	<li>
    		<a href="#">Portfilio</a>
    		<ul>
    			<li><a href="#">Link 1</a></li>
    			<li><a href="#">Link 2</a></li>
    			<li><a href="#">Link 3</a></li>
    		</ul>
    	</li>
    	<li><a href="#">Hosting</a></li>
    	<li>
    		<a href="#">JustSomeOtherStuff</a>
    		<ul>
    			<li><a href="#">Link 1</a></li>
    			<li><a href="#">Link 2</a></li>
    			<li><a href="#">Link 3</a></li>
    		</ul>
    	</li>
    	<li><a href="#">About us</a></li>
    </ul>
    as you know the words have different lengths, and I add some padding in the sides of links on 5px, and then some margin between the li's so the words isn't standing together.. everything works fine..

    I create the dropdown so it works.. but the width of the dropdown ul - I can set that to etc 160px and the menu will work.. but is there any way in css to get the width from the link without I have specified the link width? and then assign it to the sub-uls?

    so etc if we say that <a href="#">JustSomeOtherStuff</a> was 300pixel wide, then would the sub-ul to that link be the same..

    but the problem is that I don't know what content that is gonna be in the menu.. so it should scale dynamically in width, like etc if we say I changed the text from "JustSomeOtherStuff" to "HelloWorld" then the sub-ul would get same width as "HelloWorld" is in width? so I not should sit changing the CSS all the time?

    Best regards,

    Lucas Rolff

  2. #2
    Mouse catcher silver trophy Stevie D's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    5,888
    Mentioned
    122 Post(s)
    Tagged
    1 Thread(s)
    If you set
    Code:
    ul ul {width:100%;}
    that should ensure that each sub-menu is the same width as its daddy.

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2011
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stevie D View Post
    If you set
    Code:
    ul ul {width:100%;}
    that should ensure that each sub-menu is the same width as its daddy.
    ur pro! problem solved :P


Tags for this Thread

Bookmarks

Posting Permissions

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