2011-06-20 75 views
5

我明白創建類標記的一般想法,比如.center或p.center,但是執行「p.center p」之類的操作意味着什麼?我在用css創建圖片庫時看到了這樣的例子。 div.img img是什麼意思?謝謝一堆!標籤「div.img img」是什麼意思?

<html> 
<head> 
<style type="text/css"> 
div.img 
{ 
    margin: 2px; 
} 
div.img img 
{ 
    display: inline; 
    margin: 3px; 
    border: 1px solid #ffffff; 
} 
div.img a:hover img {border: 1px solid #0000ff;} 

</style> 
</head> 
<body> 
<div class="img"> 
    <a target="_blank" href="klematis4_big.htm"><img src="klematis4_small.jpg" alt="Klematis" width="110" height="90" /></a> 
</div> 
</body> 
</html> 
+0

他們不是標籤,他們選擇。 – BoltClock

回答

13

到目前爲止給出的答案都是正確的,但也許還解釋了什麼不會有所幫助。

雖然div.img img { }會影響包含在<div class="img">元素img元素,下面是它不會影響一些元素:

<body> 

    <img src="klematis4_small.jpg" alt="Klematis"><br> 
    This image is not contained in a div, therefore it cannot possibly be 
    contained in a div of the class "img" and is therefore unaffected. 

    <div> 
    <img src="klematis4_small.jpg" alt="Klematis"><br> 
    This img element is in a div, but the div is not of the class "img", 
    so the img element is unaffected. 
    </div> 

    <div id="img"> 
    <img src="klematis4_small.jpg" alt="Klematis"><br> 
    This img is contained within a div that has an ID of "img", but it is 
    also not of the class "img" and is therefore unaffected. 
    </div> 

</body> 
+2

+1非常好的例子。我爲了讓它變得更好而加入。 – BoltClock

9

這意味着

選擇任何img元件
即一個div元件的與類img的後代。

img類沒有特別的意義。這個例子看起來有點令人困惑。

+2

選擇**所有** img元素... –

+0

@ŠimeVidas:固定(有點) – BoltClock

+0

我也修復了一點點 –

3

div.img img選擇器將使用類「img」設置div內的img標籤。例如:

<div class="img"> 
    <img src="foo.jpg" alt="" /> 
</div> 

總之,只有包含具有類IMG div標籤內的img標籤將由選擇的樣式。