2010-11-12 41 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