2017-08-12 30 views
0

當我做我的CSS文件,我有這樣的:是否有合併類聲明的(純)CSS運算符?

input[type="text"], 
input[type="email"], 
input[type="password"], 
input[type="number"], 
button{ 
    padding:10px 
    border-radius:10px; 
} 

input[type="text"], 
input[type="email"], 
input[type="password"], 
input[type="number"], 
button, 
.shadow{ 
    box-shadow: .... 
} 

我可以以某種方式合併純CSS這兩個聲明,所以我會,相反,有這樣的事情:

input[type="text"], 
input[type="email"], 
input[type="password"], 
input[type="number"], 
button{ 
    padding:10px 
    border-radius:10px; 
} 
+ // some operator that would join the next class declaration on the previous declaration 
.shadow{ 
    box-shadow: .... 
} 

標題上的「純」,我的意思是沒有LESS或SASS可以做到這一點嗎?

+1

沒有,但如果你使用CSS預處理器,這個功能是相當微不足道的:) – Terry

+0

還沒有,但有一個規範草案旨在支持這個,[這裏](https ://tabatkins.github.io/specs/css-nesting/)。 – glhrmv

回答

0

沒有LESS或SASS或SCSS,這是不可能的。

有了SCSS,你可以嘗試這樣的事情。

SCSS

.shadow{ 
    box-shadow:1px 1px 1px solid red; 
} 

input[type="text"], 
input[type="email"], 
input[type="password"], 
input[type="number"], 
button{ 
    padding:10px; 
    border-radius:10px; 
    @extend .shadow; 
} 

希望這有助於..

0

沒有,但如果你只是寫這...

input[type="text"], 
input[type="email"], 
input[type="password"], 
input[type="number"], 
button{ 
    padding:10px 
    border-radius:10px; 
} 
.shadow{ 
    box-shadow: .... 
} 

...定義的box-shadow會被添加到具有shadow類的相應輸入元素,並且保持其所有其他屬性。