完整源码
您建立一个干净的 *.html 文件,或者直接选择性复制即可。
<section class="content"> <!-- 有菜单 --> <div class="items"> <div class="menu"> <span>有菜单</span> <div> <div class="drop">选项A</div> <div class="drop">选项B</div> <div class="drop">选项C</div> </div> </div> </div> <!-- END --> <!-- 无下级 --> <div class="items"> <div class="menu"> <span>无菜单</span> <div></div> </div> </div> <!-- END --> </section> /* 最外层 */ .content { display: flex; flex-direction: row; } /* END */ /* 每个菜单的样式(宽度这里调,子菜单宽度都听这个) */ .items { width: 130px; color: #fff; } /* END */ /* 菜单与鼠标移入 */ .menu{ width: 100%; height: 45px; background: red; line-height: 45px; text-align: center; position: relative; overflow: hidden; } .menu:hover{ overflow: visible; background: black; color: white; z-index: 999; cursor: pointer; } /* END */ /* 下拉菜单与鼠标移入 */ .drop{ background: red; text-align: center; width: 100%; height: 45px; line-height: 45px; overflow: hidden; } .drop:hover{ background: black; cursor: pointer; } /* END */