2010-09-03 101 views
0

我有一個被標記了,像這樣一個滑塊:這是CSS引用正確的,支持的語法:.slider.wide {}

<div class="slider wide"> 
//slider html in here 
</div> 

而另一標記像這樣:

<div class="slider narrow"> 
//slider html in here 
</div> 

是有可能通過一種方式相互引用的這些像這樣在我的CSS文件拼接類名:

.slider.wide { //css specific to the wide slider goes here } 
.slider.narrow { //css specific to the wide slider goes here } 

回答

1

是的,.slider.narrow是有效的。它並不完全連接類名,它創建了兩個不同的類選擇器並將它們應用於相同的元素。所以.narrow.slider也是有效的,並且會匹配相同的元素。

針對單個元素使用多個類選擇器的問題是,在IE6中不起作用。該瀏覽器將忽略除最後一個類選擇器以外的所有內容所以爲了支持這個瀏覽器,你通常最終會使用類似class="slider wide-slider"的東西。

+0

感謝您 - 我擔心在IE6(或者甚至任何瀏覽器)中的瀏覽器支持會成爲問題。乾杯! – Steph 2010-09-03 12:20:20

4

沒有,你讓三班.slider,你把普通的滑塊css和.narrow放在哪裏,你把窄滑塊特定的css,和.wide你放寬滑塊特定的css。

.slider { //css common among all sliders goes here } 
.wide { //css specific to the wide slider goes here } 
.narrow { //css specific to the narrow slider goes here } 
+0

球,我太慢了:D +1 – 2010-09-03 10:30:48

+0

@ILMV哈哈,我也是... – Mischa 2010-09-03 10:32:28

+0

好吧,也許我的例子有點太簡單了。我現在實際上正在查看別人的代碼並試圖解決它。 我通常會遵循你所展示的例子,但最好的做法放在一邊,如果它工作?它是無效的CSS? – Steph 2010-09-03 10:41:20