0
篇帖子
一是如何在不修改Dom结构的前提下调整布局。 二是如何判断屏幕分辨率并应用对应的CSS。
/* Phone Portrait (320px) */ @media only screen and (max-width: 320px) { #head { width: 100%; } #main { width: 100%; } #foot { width: 100%; } #left { width: 100%; } #right { width: 100%; } }
/* Phone Landscape (480px) */ @media only screen and (min-width: 321px) and (max-width: 480px) and (orientation: landscape) {
@media only screen and (-moz-min-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2/1), only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2)
<meta name="viewport" content="width=device-width; initial-scale=1.0">
1、流式布局 Liquid Layout 2、Media Query 3、viewport
Media Query的语法比较复杂,这里个大家推荐一个工具,可以方便的设计布局,并可以针对各种设备自动生成Media Query的语句:@responsivewebcss.com
附上本站的响应式设计代码参考:@199508.com
@media screen and (min-width:100px) and (max-width:450px){ #outerSidebar,#share,.pageNavi{display:none!important;} #container{width: 98%;border: 0px solid #dddddd;} #header{width: 100%;} .innerTop{width: 100%;} #content{width: 100%;} .contentTop{width: 100%;} .description{position: absolute;top: 140px;text-overflow: ellipsis;overflow: hidden;white-space: nowrap;width: 80%;} .postBody{width: 100%;} .postBodypage{width: 100%;} .blogName,.blogName a{width: 100%;} #header{width: 80%;} #footer{width: 99%;} .copyright{width: 98%;} #containerTop{width: 97%;} body{font-size:0.8em;} #innerContainer{width: 90%;} #outerContent{margin: 0 15px;width: 100%;} #posts{width: 100%;} .postHeader{width: 100%;} .postFooter{width: 95%;} textarea{width: 95%;} .reCmtBody{width: 95%;} .postHeader h2 .date{font-size: 12px;} #nav{width: 104%;float: right;font-size: 12px;} .pageNavi {text-align: center;font-size: 22px;} .pageNavipage{width: 98%;} #comments{width: 100%;} #foottextleft{text-align: left;background-color: #E4ECD9;padding: 10px;} } @media (max-width:767px){.grid-g-r>.grid-u,.grid-g-r>[class *="grid-u-"]{width:100%;}} @media (max-width: 800px) { body { font-size: 13px; } }
本博客内所有原创和翻译的文章的版权归本人所有,允许第三方转载,但转载时请务必保留作者名,并注明出处链接,否则本人将保留追究其法律责任的权利。
「人生在世,留句话给我吧」