2010-11-12 68 views
1

包裹我有一個圖像,這是float: left;確定元素是否是圍繞浮子元件

一個ul標籤解決此圖像纏繞。它位於圖像的右側。

ul中包含的自定義項目符號與浮動圖像部分重疊。

ul右移一點時,這是固定的。

但是,要做到這一點,我需要確定,ul是否纏繞在這張圖片上。

怎麼辦?


更新1:

此代碼演示了此問題。標準子彈也是如此,不僅是定製。

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title>Bullets overlapping example</title> 
</head> 
<style type="text/css" media="screen"> 
body { 
    display: block; 
    width: 400pt; 
    margin: auto; 
    border: solid thin gray; 
} 
img { 
    float: left; 
    width: 250pt; 
} 
</style> 
<body> 
<img src="http://www.hermann-uwe.de/files/images/blue_flower.preview_0.jpg" /> 
<p>Bullets in a list below must be fixed someway, to prevent overlapping of float image</p> 
<ul> 
    <li>Bullet of this list item overlaps left-hand-side image.</li> 
    <li>This list item too</li> 
    <li>And this ...</li> 
</ul> 
<div style="height: 6em;"></div> 
<p>This list should not be fixed, because it <b>does't wraps</b> the image</p> 
<ul> 
    <li>One</li> 
    <li>Two</li> 
    <li>Three</li> 
</ul> 
</body> 
</html> 

回答

1

您可以控制特定行爲使用CSS選擇器內的UL圖片:

ul img { ........ } /* This rule will apply only to images inside ULs */ 

有可能在JavaScript中,也是如此,但是這應該是可能理清使用純CSS。

+0

不,這不是我的情況。我在CSS中有「list-style-image」屬性。它不能被這樣控制 – AntonAL 2010-11-12 11:16:11

+0

@Anton ahh我明白了,如果它包含圖像,你需要解決'ul'問題? – 2010-11-12 11:21:07

+0

不,我需要「確定元素是否纏繞在浮動元素上」(請參閱​​帖子標題:)。換句話說,我需要將某些CSS樣式應用於僅有元素,該佈局被浮動元素所改變。 – AntonAL 2010-11-12 12:03:07