响应式布局和media query语法

**语法:@media not|only 设备名称[and 设备名称] ***
解释说明:
not|only not:除了某个设备,only:仅匹配某个设备
[and 设备名称可出现多次,对多个设备匹配]
设备名称:screen 代表计算机屏幕
width:可调整的宽度

 @media screen and (min-width:1000px){属性变换说明}

要想实现手机响应式布局,必须在head加上

<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!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>
</head>
<style>
    #container{
        margin: auto;
        width: 750px;
    }
    #container>div{
        border: 1px solid red;
        text-align: left;
        box-sizing: border-box;
        border-radius: 12px;
        padding: 4px;
    }
    div#left{
        width: 300px;
        height: 260px;
        float: left;
    }
    div#main{
        width: 450px;
        height: 260px;
        float: left;
        /* 清除右边的浮动 */
        clear: right;
    }
    div#right{
        width: 750px;
        float: left;
    }
    /* 浏览器宽度大于1000px的样式 */
    @media screen and (min-width:1000px){
        #container{
            margin: auto;
            width: 960px;
        }
        #container>div{
            border: 1px solid red;
            text-align: left;
            box-sizing: border-box;
            border-radius: 12px;
            padding: 4px;
        }
        div#left{
            width: 240px;
            height: 260px;
            float: left;
        }
        div#main{
            width: 460px;
            height: 260px;
            float: left;
            /* 让左右两边都可以出现float元素 */
            clear: none;
        }
        div#right{
            width: 260px;
            float: left;
            height: 260px;
        }
    }
     /* 浏览器宽度小于480px的样式 */
    @media screen and (max-width:480px){
        #container{
            margin: auto;
            width: 450px;
        }
        #container>div{
            border: 1px solid red;
            text-align: left;
            box-sizing: border-box;
            border-radius: 12px;
            padding: 4px;
        }
        div#left{
            width: 450px;
            height: 150px;
            float: left;
        }
        div#main{
            width: 450px;
            height: 260px;
            float: left;
            /* 让左右两边都不可以出现float元素 */
            clear: both;
        }
        div#right{
            width: 450px;
            float: left;
            height: 170px;
        }        
    }
</style>
<body>
    <div id="container"> 
        <div id="left">
            <h2>wwwwwwwwww</h2> 
            . . . 省略页面内容 
        </div>
        <div id="main">
             <h2>qqqqqqqqqqqqqqqq</h2>
              ... 省略页而内容 
        </div> 
        <div id="right">
            <h2>eeeeeeeeeee</h2>
             ...省略页面内容
        </div>
    </div> 
</body>
</html>

查看响应式布局方法:F12或鼠标右键->检查,调出调式框
1.在这里插入图片描述

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值