项目总结一:响应式之CSS3 媒体查询

1.<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">

viewport:视图窗口,width:视口内容宽度  initial-scale:初始时比例,不进行缩放,user-scalable=no 禁止用户触屏缩放屏幕

2.避免使用绝对单位如(px),应该使用相对单位(%,em,rem),使用流式布局,使用响应式图片。

3.Media Queries 应用

①<link rel="stylesheet" type="text/css" href="style1.css" media="screen and (min-width: 500px)">//当屏幕的宽度大于等于500px的时候,应用style1.css
②同理
@media screen and (max-width: 600px) { /*当屏幕尺寸小于600px时,应用下面的CSS样式*/
  .class {
    background: #ddd;
  }
}

以下是demo

一个三栏布局的,在不同的尺寸下,变为两栏,再变为一栏~

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>css3-media-queries-demo</title>
<style>
body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset, input, textarea, p, blockquote, th, td {
    padding: 0;
    margin: 0;
}
.content{
    zoom:1;
}
.content:after{
    content: ".";
    display: block;
    height: 0;
    clear: both;
    visibility: hidden; 
}
.leftBox, .rightBox{
    float: left;
    width: 20%;
    height: 500px;
    margin: 5px;
    background: #ffccf7;
    display: inline;
    -webkit-transition: width 1s ease;
    -moz-transition: width 1s ease;
    -o-transition: width 1s ease;
    -ms-transition: width 2s ease;
    transition: width 1s ease;
}
.middleBox{
    float: left;
    width: 50%;
    height: 800px;
    margin: 5px;
    background: #b1fffc;
    display: inline;
    -webkit-transition: width 1s ease;
    -moz-transition: width 1s ease;
    -o-transition: width 1s ease;
    -ms-transition: width 1s ease;
    transition: width 1s ease;
}
.rightBox{
    background: #fffab1;
}
@media only screen and (min-width: 1024px){
    .content{
            width: 1000px;
            margin: auto
        }
}
@media only screen and (min-width: 400px) and (max-width: 1024px){
    .rightBox{
        width: 0;
    }
    .leftBox{ width: 30%}
    .middleBox{ width: 65%}
}
@media only screen and (max-width: 400px){
    .leftBox, .rightBox, .middleBox{ 
        width: 98%;
        height: 200px;
    }
}
</style>
</head>

<body>
<div class="content">
  <div class="leftBox"></div>
  <div class="middleBox"></div>
  <div class="rightBox"></div>
</div>
</body>
</html>

  

参考文章:http://www.swordair.com/blog/2010/08/431/

     http://www.zhangxinxu.com/wordpress/2011/08/css3-media-queries%E7%9A%84%E4%BA%9B%E9%87%8E%E5%8F%B2%E5%A4%96%E4%BC%A0/

     http://webdesignerwall.com/tutorials/css3-media-queries

     http://www.ruanyifeng.com/blog/2012/05/responsive_web_design.html

              http://www.cnblogs.com/mofish/archive/2012/05/23/2515218.html

posted @ 2017-05-16 16:25  瓦克linda  阅读(211)  评论(0编辑  收藏  举报