CSS3調適型配置技術之彈性尺寸

來源:互聯網
上載者:User
網格布局支援彈性尺寸(flex-size),這是一個很好的調適型配置技術。

彈性尺寸使用fr尺寸單位,其來自 "fraction" 或 "fractional unit" 單詞的前兩個字母,表示整體空間的一部分。

比如下面的CSS規則:

grid-template-columns: 100px 1fr max-content minmax(min-content, 1fr);

表示有4列,第一列100px固定尺寸,第三列 max-content 代表剛好包含元素不溢出不換行的尺寸,剩下的2列都是彈性尺寸。

按照彈性尺寸的計算規則,兩者將均分(這兩列的彈性係數相等,均為1)剩下的可用空間。

CSS3示範代碼:

#grid {    display: grid;    width: 100%;    grid-template-columns: 100px 1fr max-content minmax(min-content, 1fr);}#title {    background-color: lime;}#score {    background-color: yellow;}#stats {    background-color: lime;}#message {    background-color: orange;}p {    height: 80px;    line-height: 80px;    text-align: center;}


HTML代碼:

<p id="grid">    <p id="title">Site Logo</p>    <p id="score">Slogan</p>    <p id="stats">User Zone</p>    <p id="message">Message</p></p>
相關文章

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.