[英]Aligning Children List Items to Parent in Dropdown Menu
I'm attempting to build a dropdown menu similar to this site . 我正在尝试建立一个类似于该站点的下拉菜单。
How do I: 我如何:
Below are some code snippets. 以下是一些代码片段。 See codepen for full code. 有关完整代码,请参见codepen 。
.nav > li > a { position: relative; display: block; z-index: 510; height: 54px; padding: 0 50px; line-height: 54px; -webkit-transition: all 0.3s ease; -moz-transition: all 0.3s ease; -o-transition: all 0.3s ease; -ms-transition: all 0.3s ease; transition: all 0.3s ease; }
<nav class="main-nav"> <ul className="nav"> <li> <a>Products</a> <div className="subnav-block"> <ul> <li> <a>Product A</a> </li> <li> <a>Product B</a> </li> </ul> </div> </li> </ul> </nav>
For aligning the children, you can make sure the children have the same padding/width as the parent. 为了对齐子代,可以确保子代与父代具有相同的填充/宽度。
.nav > li > a {
width: 200px;
padding: 0 10px;
}
.nav .subnav-block li a {
margin-left: 10px;
}
For showing all of the children on hover, simply use :hover on the parent instead of the child: 要显示所有悬停的子项,只需在父项而不是子项上使用:hover:
.nav:hover > li > .subnav-block {
opacity: 1;
visibility: visible;
overflow: visible;
}
I did some more changes, see the pen for details. 我进行了一些更改,有关详细信息,请参见笔。
https://codepen.io/davidtorresdesign/pen/agXGPY https://codepen.io/davidtorresdesign/pen/agXGPY
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.