简单的响应式布局 @media

屏幕大于1200px时,内容尺寸改变

效果图

html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="./css/demo.css"/>
    <title>Document</title>
</head>
<body>
    <div class="container">
        <header id="header">
            <h3>页头</h3>
        </header>
        <nav id="navigation">
            <h3>导航</h3>
        </nav>
        <section id="mainbody">
            <h3>主体</h3>
            <p>lalallalallalal啦啦啦啦啦啦啦啦lalallalallalal啦啦啦啦啦啦啦啦lalallalallalal啦啦啦啦啦啦啦啦lalallalallalal啦啦啦啦啦啦啦啦</p>
        </section>
        <aside id="sidebar">
            <h3>边栏</h3>
            <p>lalallalallalal啦啦啦啦啦啦啦啦lalallalallalal啦啦啦啦啦啦啦啦lalallalallalal啦啦啦啦啦啦啦啦lalallalallalal啦啦啦啦啦啦啦啦</p>
        </aside>
        <footer id="footer">
            <h3>页脚</h3>
        </footer>
    </div>
</body>
</html>

css

body{
    margin-top:40px;
    text-align: center;
}
.container{
    width: 960px;
    margin:0 auto;
}
#header, #navigation, #mainbody, #sidebar, #footer{
    line-height: 25px;
    height: 100px;
    background-color: rgb(187, 187, 187);
    margin-bottom: 20px;
}
#mainbody, #sidebar{
    float: left;
    height: 300px;
}
#mainbody{
    width: 520px;
    margin-right: 20px;
    background-color: blueviolet;
}
#sidebar{
    width: 420px;
    background-color: burlywood;
}
#footer{
    clear: both;
}
@media screen and (min-width:1200px){
    .container{
        width: 1170px;;
    }
    #mainbody{
        width: 720px;
        margin-right: 20px;
        background-color: blueviolet;
    }
    #sidebar{
        width: 430px;
        background-color: burlywood;
    }
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值