响应式导航栏

该代码示例展示了如何使用CSS媒体查询实现响应式设计,针对大屏、中屏和小屏设备调整页面布局。在大屏上,列表项并排显示,鼠标悬停时下拉菜单滑动出现。中屏和小屏设备上,布局和下拉菜单的展示方式相应改变,以适应不同的屏幕尺寸。
摘要由CSDN通过智能技术生成

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

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

    <title>Document</title>

    <style>

        *{margin: 0;padding: 0;}

        ul li{list-style: none;}

大屏样式

        @media screen and (min-width:1200px) {

            .one{

               width: 80%;

                margin: 50px auto;

                height: 40px;

                background-color: #0dc1d8;

            }

            .one>li{

                width: 20%;

                line-height: 40px;

                text-align: center;

                float: left;

                overflow: hidden;

            }

            .two{

                /* display: none; */

                transform: translateY(-250px);

                position: relative;

                z-index: -1;

            }

           

            .one>li:hover .two{

                    transform: translateY(0);

                    transition: 0.5s;

           

        }

    }

 中屏样式 

    @media screen and (min-width:768px) and (max-width:1200px) {

        .one{

            width: 300px;

            height: 400px;

            background-color: aqua;

        }

        .one>li{

            width: 100%;

            height: 50px;

            text-align: center;

            line-height: 50px;

            position: relative;

        }

        .two{

            width: 100px;

            height: 300px;

            top: 0;

            background-color: blanchedalmond;

            position: absolute;

            left: 300px;

            transform: translateX(-100px);

            z-index: -1;

        }

        .one>li:hover .two{

            transform: translateX(0);

            transition: 0.5s;

        }

    }

小屏样式

    @media screen and (max-width:768px) {

        .one{

            width: 100%;

        }

        .one li{

            width: 100%;

            height: 40px;

            text-align: center;

            line-height: 40px;

            background-color: aqua;

        }

        .two{

            width: 100%;

            height: 200px;

            /* background-color: yellow; */

            position: relative;

            z-index: -1;

            transform: translateY(-200px);

        }

        .one>li:hover .two{

            z-index: 5;

            transform: translateY(-0px);

            transition: 0.3s;

        }

       

    }

    </style>

</head>

<body>

    <ul class="one">

        <li>1613</li>

        <li>9634</li>

        <li>45174

            <ul class="two">

                <li>1613</li>

                <li>9634</li>

                <li>45174</li>

                <li>5744</li>

                <li>7845</li>

            </ul>

        </li>

        <li>5744</li>

        <li>7845</li>

    </ul>

</body>

</html>

效果图

大屏效果                                中屏效果                                    小屏效果

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值