美文网首页
Html5响应式布局——实例

Html5响应式布局——实例

作者: hello青峰 | 来源:发表于2016-02-09 22:21 被阅读0次

    一个简单的实例(类似一淘网etao.com),版面包含头部、尾部,中间分为3个部分。随着宽度的缩小,一次隐藏中间right的部分,再缩小把right放在中间部分的下面。
    包含2个文件:index.html 和 style.css
    index.html:


    index.html.png

    style.css:

    /* 初始化---begin */
    *{     
        margin: 0px;     
        padding: 0px;
    }
    .heading,
    .container,
    .footing{   
        margin: 10px auto;// 上下10px,左右自适应
    }
    .heading{    
        height: 100px;    
        background-color: chocolate;
    }
    .left,
    .right,
    .main{    
        background-color: cornflowerblue;
    }
    .footing{    
        height: 100px;    
        background-color: blue;
    }
    /* 初始化---end */
    
    /* 自适应---begin */
    /*屏幕宽度大于960*/
    @media screen and (min-width: 960px){   
    .heading,    
    .container,   
    .footing{        
        width: 960px;    
    }    
    .left,    
    .main,   
    .right{        
        float: left;       
        height: 500px;   
     }    
    .left,    
    .right{        
        width: 200px;    
    }    
    .main{        
        margin: 1px 5px;       
        width: 550px;    
    }    
    .container{       
        height: 500px;    
    }
    }
    
    /*屏幕宽度大于600小于960*/
    @media screen and (min-width: 600px) and (max-width:960px) {    
    .heading,    
    .container,    
    .footing{        
        width: 600px;   
    }    
    .left,    
    .main{        
        float: left;        
        height: 400px;    
    }    
    .right{        
        display: none;    
    }    
    .left{        
        width: 160px;   
    }    
    .main{        
        width: 435px;        
        margin-left: 5px;    
    }    
    .container{        
        height: 400px;    
    }
    }
    
    /*屏幕宽度小于600*/
    @media screen and (max-width:600px) {    
    .heading,    
    .container,   
    .footing{        
        width: 400px;    
    }    
    .left,    
    .right{        
        width: 400px;        
        height: 100px;    
    }    
    .main{        
        margin-top: 10px;        
        width: 400px;        
        height: 200px;   
    }    
    .right{        
        margin-top: 10px;    
    }    
    .container{        
        height: 420px;    
    }
    }
    /* 自适应---end */

    相关文章

      网友评论

          本文标题:Html5响应式布局——实例

          本文链接:https://www.haomeiwen.com/subject/rdnykttx.html