詳解實現網頁布局的自適應@media screen

來源:互聯網
上載者:User
利用@media screen實現網頁布局的自適應

優點:無需外掛程式和手機主題,對行動裝置友好,能夠適應各種視窗大小。只需在CSS中添加@media screen屬性,根據瀏覽器寬度判斷並輸出不同的長寬值

1280解析度以上(大於1200px)

@media screen and (min-width:1200px){    #page{ width: 1100px; }#content,.div1{width: 730px;}#secondary{width:310px}}

1100解析度(大於960px,小於1199px)

@media screen and (min-width: 960px) and (max-width: 1199px) {    #page{ width: 960px; }#content,.div1{width: 650px;}#secondary{width:250px}select{max-width:200px}}

880解析度(大於768px,小於959px)

@media screen and (min-width: 768px) and (max-width: 959px) {    #page{ width: 900px; }#content,.div1{width: 620px;}#secondary{width:220px}select{max-width:180px}}

720解析度(大於480px,小於767px)

@media only screen and (min-width: 480px) and (max-width: 767px){    #page{ width: 450px; }#content,.div1{width: 420px;position: relative; }#secondary{display:none}#access{width: 450px; }#access a {padding-right:5px}#access a img{display:none}#rss{display:none}#branding #s{display:none}}

440解析度以下(小於479px)

@media only screen and (max-width: 479px) {    #page{ width: 300px; }#content,.div1{width: 300px;}#secondary{display:none}#access{width: 330px;} #access a {padding-right:10px;padding-left:10px}#access a img{display:none}#rss{display:none}#branding #s{display:none}#access ul ul a{width:100px}}
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.