响应式布局

<!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: rgb(73, 197, 156);
            }
            .one>li{
                float: left;
                width: 20%;
                line-height: 40px;
                text-align: center;
                overflow: hidden;
            }
            .two{
                /* display: none; */
                /* position: relative; */
                transform: translateY(-250px);
                z-index: -1;
            }
            .two li{
                background-color: aqua;
            }
            .one>li:hover .two{
                display: block;
                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{
                position: absolute;
                left: 300px;
                width: 100px;
                top: 0;
                background-color: blanchedalmond;
                height: 300px;
                transform: translate(-100px,-20PX);
                z-index: -1;
            }
            .one>li:hover .two{
                transform: translate(0,20PX);
                
                transition: 0.5s;
            }
        }
        @media screen and (max-width:768px){
            .one{
                width: 100%;                
            }
            .one li{
                width: 100%;
                text-align: center;
                height: 40px;
                line-height: 40px;
                background-color: rgb(40, 190, 177);
            }
            .two{
                width: 100%;
                height: 200px;
                position: relative;
                z-index: -1;
                transform: translateY(-250px);
            }
            .one>li:hover .two{
                transform: translateY(0px);
                transition: 0.3s;
                z-index: 5;
            }
        }
    </style>
</head>
<body>
    <ul class="one">
        <li>首页</li>
        <li>22</li>
        <li>咨询
            <ul class="two">
                <li>1</li>
                <li>2</li>
                <li>1</li>
                <li>1</li>
                <li>1</li>
            </ul>
        </li>    
        <li>售后</li>
        <li>客服</li>
    </ul>
</body>
</html>

响应式布局:根据屏幕大小,显示合适的内容。

响应式开发的原理是使用CSS3中的Media Query(媒体查询)针对不同宽度的设备设置不同的布局和样式,从而适配不同的设备。

CSS3 @media 查询定义和使用:

使用 @media 查询,你可以针对不同的媒体类型定义不同的样式。@media 可以针对不同的屏幕尺寸设置不同的样式,特别是如果你需要设置设计响应式的页面,@media 是非常有用的。当你重置浏览器大小的过程中,页面也会根据浏览器的宽度和高度重新渲染页面。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_58801166

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值