鑑於這種LESS混入:LESS - 分配混入變量和重用
#gradient {
.vertical (@startColor: #555, @endColor: #333) {
background-color: @endColor;
background-repeat: repeat-x;
background-image: -khtml-gradient(linear, left top, left bottom, from(@startColor), to(@endColor)); /* Konqueror */
background-image: -moz-linear-gradient(@startColor, @endColor); /* FF 3.6+ */
background-image: -ms-linear-gradient(@startColor, @endColor); /* IE10 */
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, @startColor), color-stop(100%, @endColor)); /* Safari 4+, Chrome 2+ */
background-image: -webkit-linear-gradient(@startColor, @endColor); /* Safari 5.1+, Chrome 10+ */
background-image: -o-linear-gradient(@startColor, @endColor); /* Opera 11.10 */
filter: e(%("progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=0)",@startColor,@endColor)); /* IE6 & IE7 */
-ms-filter: %("progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=0)",@startColor,@endColor); /* IE8+ */
background-image: linear-gradient(@startColor, @endColor); /* the standard */
}
}
它通常會被稱爲如下樣式的頁眉/頁腳:
header {
#gradient > .vertical(@black, @white);
width: 100%;
}
footer {
#gradient > .vertical(@black, @white);
padding: 20px;
}
這工作沒有任何問題。但是,我試圖將#gradient > .vertical(@black, @white);
分配給變量gradient1
並重新使用它。所以像這樣理想:
@gradient1: #gradient > .vertical(@black, @white);
@headerBackground: @gradient1;
@footerBackground: @gradient1;
header { @headerBackground; width: 100%; }
footer { @footerBackground; padding: 20px; }
這不起作用 - 但如何解決這個問題?
歡迎使用Stack Overflow,並感謝您發佈第一篇文章的格式良好的問題。 – ScottS
這兩個答案都很棒!謝謝你們倆。 –