CSS | 导航栏下拉菜单淡入淡出

强颜欢笑 提交于 2019-11-27 02:36:34

  HTML文档:

<div class="drop_bar">
        <ul class="drop_bar">
            <li><a href="#home" class="active" target="_blank">主页</a></li>
            <div class="drop_down">
                <a id="drop_menu" href="#introduce" target="_blank">部门介绍</a>
                <div class="drop_content">
                    <a href="#media" target="_blank">新媒体运营部</a>
                    <a href="#maker_service" target="_blank">创客服务部</a>
                    <a href="#vip_service" target="_blank">会员服务部</a>
                    <a href="#office" target="_blank">综合办公室</a>
                </div>
            </div>
            <li><a href="#contect" target="_blank">联系我们</a></li>
        </ul>
    </div>

  CSS:

ul.drop_bar {
    position: relative;
    width: 93%;
    height: 50px;
    background-color: #333;
    list-style-type: none;
    /*实现居中*/
    margin: auto;
    padding: 0;
}

ul.drop_bar li {
    width: 33.33%;
    float: left;
    margin: 0;
}

ul.drop_bar li a {
    /*让整个区域成为可点击的*/
    display: block;
    color: white;
    padding: 14px 10px;
    text-decoration: none;
    text-align: center;
    outline: none;
    transition-duration: 0.4s;
}

ul.drop_bar li a.active {
    background-color: #111;
}

ul.drop_bar li a:hover:not(.active) {
    background-color: #111;
}

div.drop_down {
    width: 33.33%;
    float: left;
    overflow: hidden;
    transition-duration: 0.4s;
}

div.drop_down:hover a#drop_menu {
    background-color: #111;
}

div.drop_down:hover div.drop_content {
    opacity: 1;
}

div.drop_down a {
    display: block;
    text-align: center;
    text-decoration: none;
    color: white;
    background-color: #333;
    padding: 14px 10px;
    outline: none;
    transition-duration: 0.4s;
}

div.drop_content {
    display: block;
    position: relative;
    z-index: 2;    /*解决堆叠问题*/
    box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.5);
    clear: both;
    opacity: 0;
    transition-duration: 0.7s;
}

div.drop_content a:hover {
    background-color: #111;
}

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