我需要父菜单后面的子菜单。看看图片(左边是默认的浏览器渲染,如果我正在使用绝对的div,但我需要它像右边一样):
http://i67.tinypic.com/2nuqb89.jpg
子菜单应位于父菜单后面,以避免重叠。我尝试了一些z-index的东西,但它确实没有用。像z-index一样:-1可能会解决第一个子菜单的问题,但不会解决第二个子菜单的问题,对吗?
也许这个小提琴让它更清晰:
html, body {
height: 100%;
background: darkred;
padding: 0;
margin: 0;
}
ul, li {
list-style: none;
margin: 0;
padding: 0;
}
a {
display: block;
color: darkred;
text-decoration: none;
padding: 1rem 2rem;
}
.mainmenu {
width: 10rem;
background: white;
position: fixed;
height: 100%;
z-index: 99;
}
.mainmenu li:hover > ul {
left: 100%;
}
.mainmenu__sub {
width: 10rem;
position: absolute;
left: 0;
top: 0;
z-index: -2;
transition: all 0.3s ease-in-out;
}
.mainmenu__sub--red {
background: red;
}
.mainmenu__sub--green {
background: green;
}
<ul class="mainmenu">
<li><a href="javascript:;">Menu1</a>
<ul class="mainmenu__sub mainmenu__sub--red">
<li><a href="javascript:;">Submenu1</a>
<ul class="mainmenu__sub mainmenu__sub--green">
<li><a href="javascript:;">Subsubmenu1</a></li>
<li><a href="javascript:;">Subsubmenu2</a></li>
<li><a href="javascript:;">Subsubmenu3</a></li>
</ul>
</li>
<li><a href="javascript:;">Submenu2</a></li>
<li><a href="javascript:;">Submenu3</a></li>
</ul>
</li>
<li><a href="javascript:;">Menu2</a></li>
<li><a href="javascript:;">Menu3</a></li>
<li><a href="javascript:;">Menu4</a></li>
</ul>
tldr;我需要反转子/父z-index行为
答案 0 :(得分:1)
根据以下代码在即时嵌套@IBAction func buttonTap(_ sender: UIButton) {
//remove previous notifications
postNotificationReloadMainPageVC()
}
中添加相同的颜色。
li
html, body {
height: 100%;
background: darkred;
padding: 0;
margin: 0;
}
ul, li {
list-style: none;
margin: 0;
padding: 0;
}
a {
display: block;
color: darkred;
text-decoration: none;
padding: 1rem 2rem;
}
.mainmenu {
width: 10rem;
background: white;
position: fixed;
height: 100%;
z-index: 99;
}
.mainmenu > li{
background: white;
}
.mainmenu li:hover > ul {
left: 100%;
}
.mainmenu__sub {
width: 10rem;
position: absolute;
left: 0;
top: 0;
z-index: -2;
transition: all 0.3s ease-in-out;
}
.mainmenu__sub--red, .mainmenu__sub--red > li {
background: red;
}
.mainmenu__sub--green, .mainmenu__sub--green > li {
background: green;
}