必看的css布局小技巧分享

來源:互聯網
上載者:User
下面小編就為大家帶來一篇必看的css布局小技巧分享。小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

1.max-width:

當頁面左右寬度縮小時,為了避免出現左右捲軸的糟糕體驗,就可以用到max-width啦!頁面比寬度小時,會自動縮小哦~

max-width : 500px;   margin: 0 auto;   }

2.box-sizing:

對元素設定box-sizing:border-box後,確定寬度後再設定padding和border,不會改變寬度。可以對全域設定,解決瀏覽器安全色問題的寫法如下:

-webkit-box-sizing : border-box;   -moz-box-sizing:border-box;   box-sizing:border-box;    }

3.overflow:auto

邊框自適應內容的大小,不會出現overflow的情況。

IE相容方案:

.example{ overflow:auto; zoom:1; }

4.響應式設計-媒體查詢

運用媒體查詢後,可以根據不同的頁面寬度設定不同的布局,方法如下:

//頁面寬度大於600px時,nav模組浮動於左側   @media screen and (min-width: 600px) {   nav {       float: left;       width: 25%;   }   section {       margin-left: 25%;   }   }   //頁面寬度小於599時,nav模組打橫,在上方   @media screen and (max-width: 599px) {   nav li {       display: inline;   }   }

5.文字多欄版面配置:

.three-column { padding :1em; -moz-column-count :3; -moz-column-gap: 1em; -webkit-column-count :3; -webkit-column-gap: 1em; column-count:3; column-gap:1em; }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.