2012-06-18 28 views
0

我怎麼可以這樣寫,因此針對這兩種元素,而無需編寫了兩次如何定位和輸入功能與同一個類中選擇元素

.field_with_errors input{ 
    color: red; 
    background: #CEF6EC; 
    border: 1px solid red; 
} 


.field_with_errors select{ 
    color: red; 
    background: #CEF6EC; 
    border: 1px solid red; 
} 

這不起作用

.field_with_errors select input{ 
    color: red; 
    background: #CEF6EC; 
    border: 1px solid red; 
} 

回答

4
.field_with_errors select, 
.field_with_errors input { 
    color: red; 
    background: #CEF6EC; 
    border: 1px solid red; 
} 

多個CSS選擇器必須用逗號分隔。如上所述,您必須爲每個選擇器重複整個選擇器。

還,這是一個常見的做法是讓每個逗號後是一個換行符,讓你的CSS可讀性更強 - 它不會影響結果,所以下面的意思是相同的:

.field_with_errors select, 
.field_with_errors input { 

.field_with_errors select, .field_with_errors input { 
+0

感謝您的出色答案 – chell

1
.field_with_errors input,.field_with_errors select{ 
    color: red; 
    background: #CEF6EC; 
    border: 1px solid red; 
} 
相關問題