简体   繁体   English

使第二级 ul 为第一个 ul 的 100% 高度,而不是父 li

[英]Making 2nd level ul 100% height of the first ul instead of the parent li

I have this menu http://codepen.io/alexandernst/pen/oxpGYQ (tried to insert it here but SO's result viewer is breaking the demo...) and I want to make the second and third level ul elements the same height as the first level ul and also start at the same position (which would be top: 0 is this concrete demo) as the first ul element.我有这个菜单http://codepen.io/alexandernst/pen/oxpGYQ (试图在这里插入它,但结果查看器正在破坏演示......)我想让第二级和第三级ul元素具有相同的高度作为第一级ul并且也从与第一个 ul 元素相同的位置(这将是top: 0是这个具体演示)开始。

So, said with other words, I want all ul elements to start at the tom of the row div and have 100% height.因此,换句话说,我希望所有ul元素都从row div 的开始处开始并具有 100% 的高度。

Note that I don't know how many li elements I'll have, so I can't hardcode top values for each ul element in order to adjust it's top position.请注意,我不知道我将拥有多少个li元素,因此我无法对每个ul元素的top值进行硬编码以调整其top位置。

I'd like to avoid having to use javascript, but if there is no other way I could accept an answer with JS.我想避免使用 javascript,但如果没有其他方法,我可以接受 JS 的答案。

Try giving position static to the li elements.尝试为li元素赋予位置static Then when setting height: 100% to the ul element it be will relative to the parent ul instead of the parent li .然后,当将height: 100%设置为ul元素时,它将相对于父ul而不是父li So long as the ul element has position set to relative , absolute or fixed .只要ul元素的位置设置为relativeabsolutefixed

Add this CSS添加这个 CSS

#cssmenu ul li {
  position: static !important;
}

#cssmenu ul ul {
  top: 0;
  height: 100%;
  background: #1b9bff;
}

Here is the Codepen solution: http://codepen.io/anon/pen/KzZXxv这是 Codepen 解决方案: http ://codepen.io/anon/pen/KzZXxv

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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