你的位置:首页 > 软件开发 > 网页设计 > [转]响应式web设计之CSS3 Media Queries

[转]响应式web设计之CSS3 Media Queries

发布时间:2015-05-27 00:00:06
开始研究响应式web设计,CSS3 Media Queries是入门。Media Queries,其作用就是允许添加表达式用以确定媒体的环境情况,以此来应用不同的样式表。换句话说,其允许我们在不改变内容的情况下,改变页面的布局以精确适应不同的设备。那么,Media Queries ...

[转]响应式web设计之CSS3 Media Queries

开始研究响应式web设计,CSS3 Media Queries是入门。

Media Queries,其作用就是允许添加表达式用以确定媒体的环境情况,以此来应用不同的样式表。换句话说,其允许我们在不改变内容的情况下,改变页面的布局以精确适应不同的设备。

那么,Media Queries是如何工作的?

两种方式,一种是直接在link中判断设备的尺寸,然后引用不同的css文件:

<link rel="stylesheet" type="text/css" href="styleA.css" media="screen and (min-width: 400px)">
<!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 > <div ></div> <div ></div> <div ></div></div></body></html>
[转]响应式web设计之CSS3 Media Queries

参考文章: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


原标题:[转]响应式web设计之CSS3 Media Queries

关键词:CSS

CSS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。