W3Cschool
恭喜您成為首批注冊用戶
獲得88經驗值獎勵
話雖如此,混合宏確實非常有用,你應該學習使用它。經驗告訴我們,如果你發(fā)現有一組 CSS 屬性經常因同一個原因一起出現(非巧合),那么你就可以使用混合宏來代替。比如Nicolas Gallagher的清除浮動應當放入一個混合宏的實例。
/// Helper to clear inner floats
/// @author Nicolas Gallagher
/// @link http://nicolasgallagher.com/micro-clearfix-hack/ Micro Clearfix
@mixin clearfix {
&::after {
content: '';
display: table;
clear: both;
}
}
另一個有效的實例是通過在混合宏中綁定?width
?和?height
?屬性,可以為元素設置寬高。這樣不僅會淡化不同類型代碼間的差異,也便于閱讀。
/// Helper to size an element
/// @author Hugo Giraudel
/// @param {Length} $width
/// @param {Length} $height
@mixin size($width, $height: $width) {
width: $width;
height: $height;
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯系方式:
更多建議: