CSS3 calc() 會計算的屬性

來源:互聯網
上載者:User

標籤:support   解決   計算   height   百分比   style   相容性   data   keyword   

CSS3 calc() 會計算的屬性

calc是英文單詞calculate(計算)的縮寫,是css3的一個新增的功能,你可以使用calc()給元素的border、margin、pading、font-size和width等屬性設定動態值。

以前我們可以使用box-sizing:border-box;來設定盒子的屬性為不加上邊距。現在我們又多了一個選擇了。但要注意,兩者只能使用一個哦,否則就會造成衝突了。

怎麼使用

calc()可以使用數學運算中的簡單加(+)、減(-)、乘(*)和除(/)來解決問題,而且還可以根據單位如px,em,rem和百分比來轉化計算。

比如三局平均分布的布局,中間間距為5像素。

 


*{margin: 0; padding: 0;}.col-3{width: calc(100%/3 - 5px); float: left; margin-right: calc(5px*3 /2); background: #eee; color: #333; height: 100px; text-align: center; margin-bottom: calc(5px*3 /2); font-size: 18px; line-height: 100px;}.col-3:nth-child(3){margin-right: 0;}


瀏覽器安全色性

CSS3 calc() 會計算的屬性

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.