How do I force nested list items to be the same width as parent list item?

删除回忆录丶 提交于 2019-12-04 03:17:45

I did the change on your fiddle. http://jsfiddle.net/BXnxc/2/

The parent li needs to have position:relative; and the nested submenu has to have width:100%; and position:absolute;

You can do this by specifying the parent LI as relative and child UL with width: 100%

Demo: http://jsfiddle.net/BXnxc/3/

.horizontalMenu li {    
    position: relative;
}
.horizontalMenu li ul {    
    width: 100%;   
}

You can also do this by inheriting the width of the containing structures. I set your mainMenu div to width of 200px and then width:inherit for the mainSubMenu.

http://jsfiddle.net/BXnxc/4/

.mainMenu a, .mainMenu div{
    display: block;
    padding: 10px 20px; 
    width:200px;
}
.mainSubMenu{
    position: absolute;
    width:inherit;
}

.mainSubMenu li
{
    display: block;
    border: 1px solid grey; 
    width:inherit; 
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!