响应式布局初体验

响应式布局初体验

1.兼容移动端
 <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
2.媒体查询
    <style type="text/css">
         /*这里是兼容PC端的显示界面*/   
        @media only screen and (min-width: 768px) {
            body{
                background: red;
            }

        }
        /*这里是兼容移动端的显示*/     
        @media only screen and (min-width: 320px )and (max-width:768px)  {
            body{
                background: #ddd;
            }

        }
    </style>
3.简单样例

    <!DOCTYPE html>
    <html>

    <head>
        <meta charset="utf-8" />
        <title></title>
        <!--兼容移动端-->
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        <style type="text/css">
            * {
                margin: 0;
                padding: 0;
            }

            @media only screen and (min-width: 768px) {
                header {
                    height: 40px;
                    width: 1008px;
                    border-radius: 5px 5px 0px 0px;
                    margin: 0 auto;
                    background: #000;
                }
                header ul {
                    list-style: none;
                }
                header ul li {
                    float: left;
                    color: #fff;
                    height: 40px;
                    line-height: 40px;
                    width: 100px;
                    text-align: center;
                }
                .top{
                    display: none;
                }
            }

            @media only screen and (min-width: 100px)and (max-width:768px) {
                header{
                    height: 40px;
                    width: 100%;
                }
                header ul {
                    list-style: none;
                    display: block;
                }
                header ul li {
                    height: 40px;
                    line-height: 40px;
                    display: block;
                    text-indent: 20px;
                }
                header ul li:hover{
                    background: #CCCCCC;
                }
                .top{
                    display: block;
                        height: 40px;
                    border-bottom: 2px solid #ccc;
                }
                .logo{
                    float: left;
                    font-family: "微软雅黑";
                    line-height: 40px;
                }
                .navbar{
                    width: 40px;
                    height: 40px;
                    float: right;   
                    margin-top: 10px;           
                }
                .navbar span{
                    display: block;
                    width: 20px;
                    height: 6px;
                    border-bottom:1px solid #000 ;
                }
            }
            /*媒体查询*/
            /*@media only screen and (min-width: 768px) {
                body{
                    background: red;
                }

            }

            @media only screen and (min-width: 320px )and (max-width:767px)  {
                body{
                    background: #ddd;
                }

            }*/
        </style>
    </head>

    <body>
        <div id="top">
            <header>
                <div class="top">
                    <div class="logo">
                        公司网站
                    </div>
                    <div class="navbar">
                        <span></span>
                        <span></span>
                        <span></span>
                    </div>
                </div>
                <ul>
                    <li>首页</li>
                    <li>关于我们</li>
                    <li>产品中心</li>
                    <li>新闻资讯</li>
                    <li>招聘</li>
                    <li>联系我们</li>
                </ul>
            </header>
        </div>

    </body>

    </html>
4.使用css外部链接方式
    <link rel="stylesheet" type="text/css" href="css/index_pc.css" media="only screen and (min-width:768px)" />
    <link rel="stylesheet" type="text/css" href="css/index_phone.css" media="only screen and (min-width:100px) and (max-width:767px)" />
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值