断断续续的学了一个月的html和css了,最近因为备战中考所以暂时搁置了,今天有空就写了一个二级菜单的代码,分享给大家,本二级下拉菜单是利用hover和transform实现菜单的出现与隐藏,横拉菜单与此相似,只是方向不同

效果图:

现在上代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>二级菜单</title>
    <style>
        *{
            list-style:none;
            margin:0;
            padding:0;
        }
        .shell{
            display: flex;
            justify-content: center;
        }
        .butten{
            background-color:  #50536e;
            width: 170px;
            height: 65px;
            text-align: center;
            line-height: 65px;
            transition: .3s;
            cursor: pointer;
        }
        .butten:hover{
            background-color: #d15a29;
        }
        .butten li:hover{
            background-color: #ffb29d;
        }
        .butten ul li{
            height: 0px;
            transform: .2s;
            opacity: 0;
            transform: translateY(-65px);
            background-color: #e02a5f;
        }
        .butten:hover li{
            height: 65px;
            opacity: 1;
            transform: translateY(0);
        }
        .menus{
            background-color: antiquewhite;

        }
    </style>
</head>
<body>
<div class="menus">
    <ul class="shell">
        <li class="butten">
            <span>一级菜单1</span>
                <ul>
                    <li>二级菜单1</li>
                    <li>二级菜单1</li>
                    <li>二级菜单1</li>
                    <li>二级菜单1</li>
                </ul>
        </li>
        <li class="butten">
            <span>一级菜单2</span>
                <ul>
                    <li>二级菜单2</li>
                    <li>二级菜单2</li>
                    <li>二级菜单2</li>
                    <li>二级菜单2</li>
                </ul>
        </li>
        <li class="butten">
            <span>一级菜单3</span>
                <ul>
                    <li>二级菜单3</li>
                    <li>二级菜单3</li>
                    <li>二级菜单3</li>
                    <li>二级菜单3</li>
                </ul>
        </li>
        <li class="butten">
            <span>一级菜单4</span>
                <ul>
                    <li>二级菜单4</li>
                    <li>二级菜单4</li>
                    <li>二级菜单4</li>
                    <li>二级菜单4</li>
                </ul>
        </li>
    </ul>
</div>
<!--双皮酸奶的酸奶盒:shuangpisuannai.topsssss-->
</body>
</html>

希望这个能够帮到大家qwq