简体   繁体   中英

Sub menu 100% width of menu

I have a sub menu appear below my main menu. The main menu is a fixed width, I would like the sub menu to be 100% width of the main menu. The sub menu could contain any number of links, I would like the width of the sub menu to change proportionately. Is this possible? Here's my code:

Fiddle

CSS

#nav a{
width: 115px;
height: 15px;
text-decoration:none;
display:block;
font-size:12px;
font-family: Arial, Verdana, Helvetica, sans-serif;
text-align:center;
color:#666666;
border: 1px solid green;
float: right;
padding: 10px 5px 5px 5px;
z-index: 2000;
}

#nav a li{
width: 115px;
height: 15px;
}

#nav:last-child {
border-right: 1px solid #999999; 
}

#nav a:active, #nav a:hover, #nav a:focus {
background: #999 ;
}
#nav li { 
display:block;
float:left;
}
#nav li:last-child {
border-right: 1px solid #999999; 
}
#nav li ul { 
display: table;
height: 30px;
position: absolute;
left: -9999px;
}
#nav li:hover ul {
left: 0; 
top: 30px; 
}
#nav li li {
display: table-cell;
}
#nav li li a{
text-decoration:none;
display:block;
font-size:9px;
font-family: Arial, Verdana, Helvetica, sans-serif;
text-align:center;
border-left: 1px solid #999999; 
color:#666666;
z-index: 10000;
padding: 5px 5px 10px 5px;
}

HTML

<ul id="nav">
<li><a href="#">LINK1</a></li>
<li><a href="#">LINK2</a>
    <ul>
    <li><a href="#">LINK3 <br> MORE TEXT</a></li>
    <li><a href="#">LINK4</a></li>
    <li><a href="#">LINK5</a></li>
    <li><a href="#">LINK6</a></li>
    </ul></li>
<li><a href="#">LINK7</a></li>
<li><a href="#">LINK2</a>
    <ul>
    <li><a href="#">LINK3 <br> MORE TEXT</a></li>
    <li><a href="#">LINK4</a></li>
    <li><a href="#">LINK5</a></li>
    <li><a href="#">LINK6</a></li>
    <li><a href="#">LINK5</a></li>
    </ul></li>
</ul>

Thanks!

I don't know if I understand the question.

You need to wrap both of the menus in a div. Then if subnav has 100% width, it will adopt the width of that div.

Do you have a link. If I can see what you are talking about I can help further.

#nav li applies to ALL li inside #nav , even if the li is several layers down. That is to say — the submenu li are still considered #nav li . To override that rule, set #nav li li to width:auto !important; or something.

But to accomplish what (I think) you actually want to do, try adding this:

#nav
{
width:660px;
position:relative;
}

#nav ul
{
display:table;
width:100%;
position:absolute;
top:30px;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM