案例:下拉菜单

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <title>Document</title>

    <style>

        *{

            margin: 0;

            padding: 0;

            font: 30px / 90px "微软雅黑";

        }

        ul{

            list-style: none;

        }

        .wrap{

            width: 1000px;

            height: 1000px;

            position: absolute;

            left: 50%;

            top: 50%;

            margin-top: -500px;

            margin-left: -500px;

            background: url(img/bg.jpg) no-repeat;

        }

        .menu{

            width: 330px;

            border-radius: 10px;

            overflow: hidden;

            margin-top: 285px;

            margin-left: 335px;

            background: #f87a75;

            box-shadow: 0 20px 50px rgba(248,122,117,.5);

        }

        .title{

            height: 90px;

            padding-left: 112px;

            box-sizing: border-box;

            color: #fff;

            position: relative;

        }

        .title::after{

            content: '';

            position: absolute;

            right: 36px;

            top: 41px;

            background: url(img/ar.png) no-repeat ;

            width: 28px;

            height: 16px;

        }

        .list{

            width: 316px;

            padding-left:7px; 

            padding-bottom: 5px;

            display: none;

        }

        .list li{

            height: 90px;

            margin-bottom: 2px;

            background:#fee4e3;

            border-radius: 20px;

            padding-left: 112px;

            box-sizing: border-box;

            background-position: 23px 24px;

            background-repeat: no-repeat;

        }

        .list li:hover{

            background-color: #fff;

            box-shadow:0 0 50px rgba(248,122,117,0.93);

            position: relative;

        }

        .list li:nth-of-type(1){

            background-image: url(img/icon1.png);

        }

        .list li:nth-of-type(2){

            background-image: url(img/icon2.png);

        }

        .list li:nth-of-type(3){

            background-image: url(img/icon3.png);

        }

        .list li:nth-of-type(4){

            background-image: url(img/icon4.png);

        }

        .list li:nth-of-type(5){

            background-image: url(img/icon5.png);

        }

    </style>

</head>

<body>

<div class="wrap">

    <div class="menu">

        <div class="title">菜单</div>

        <ul class="list">

            <li>微博</li>

            <li>图片</li>

            <li>博客</li>

            <li>视频</li>

            <li>更多>></li>

        </ul>

    </div>

</div>

<script>

{

    let list = document.querySelector(".list");

    let menu = document.querySelector(".menu");

    let title = document.querySelector(".title")

    menu.addEventListener("click",function(e){

        if(getComputedStyle(list)["display"] === "none"){

            list.style.display = "block";

        } else {

            list.style.display = "none";

        }

        e.stopPropagation();//阻止冒泡

        console.log(e.target.innerHTML);

        if(e.target.tagName == "LI"&& e.target.innerHTML !== "更多&gt;&gt;"){

            title.innerHTML = e.target.innerHTML;

        }

    });

    document.addEventListener("click",function(){

        list.style.display = "none";

    });

}

</script>

</body>

</html>

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1. tab列表折叠效果 html: 能源系统事业部 岗位名称: 工作地点 岗位名...
    lilyping阅读 2,007评论 0 1
  • 本书介绍 你是不是对Django的学习感到迷茫?是不是对网上零星的教程感到绝望?是不是苦于没有可以迅速上手的实例而...
    阡陌3536阅读 1,400评论 0 0
  • width: 65%;border: 1px solid #ddd;outline: 1300px solid #...
    邵胜奥阅读 5,105评论 0 1
  • 这篇文字里我会介绍50 个便于使用的 CSS2/CSS3 代码片段给所有的WEB专业人员. 选择IDE开发环境来存...
    JamHsiao_aaa4阅读 1,532评论 0 3
  • 一、CSS入门 1、css选择器 选择器的作用是“用于确定(选定)要进行样式设定的标签(元素)”。 有若干种形式的...
    宠辱不惊丶岁月静好阅读 1,706评论 0 6

友情链接更多精彩内容