整个文本文章中的多个浮动图像
CSS 有问题,我想我想要的东西没有 JavaScript 是可能的,但我不确定。
我有一篇文本文章,我想用 0-3 张图像来显示(每篇文章的数量都是动态的)。我想将 3 个图像全部显示在页面的右侧,它们之间的距离约为 200-300px。我仅通过浮动图像、使用清晰和边距就取得了这些成就。
我无法做到的部分是允许文本在 200-300px 的空间中的图像之间流动。我尝试过相对定位将图像下推到我想要它们的页面部分,但是通过浮动它们在文本中为它们保留的空白保留在原来的位置(即图像最终位于文本顶部) 。
没有js也可以实现吗?文本也是完全动态的,因此我无法使用文本中的任何元素作为锚点。
编辑:这里有一些代码来解释一下:
标签:
<div>
<img class="floater" src="get_file.asp?image=1"/>
<img class="floater" src="get_file.asp?image=2"/>
<img class="floater" src="get_file.asp?image=3"/>
<p>lots and lots of text and paragraphs go here....</p>
</div>
CSS:
.floater
{
float:right;
height:250px;
clear:both;
margin-top:200px;//This creates space between the images, but the text doesn't flow between them
}
Having problems with CSS, and I think what I want is possible without javascript, but I'm not sure.
I have an article of text that I want to display with 0-3 images(The number is dynamic for each article). I want to display the 3 images all on the right-hand side of the page, with about 200-300px between them. This much I have achieved just by floating the images, using clear, and margins.
The part I haven't been able to do is allow the text to flow between the images in that 200-300px worth of space. I've tried relative positioning to push the images down to the part of the page I want them at, but the blank space reserved for them in the text by floating them stays where it is (i.e. the image ends up on top of text).
Is this even possible without js? The text is also completely dynamic, so I can't use any element in the text as an anchor.
EDIT: Here's some code to explain a little:
The tags:
<div>
<img class="floater" src="get_file.asp?image=1"/>
<img class="floater" src="get_file.asp?image=2"/>
<img class="floater" src="get_file.asp?image=3"/>
<p>lots and lots of text and paragraphs go here....</p>
</div>
The CSS:
.floater
{
float:right;
height:250px;
clear:both;
margin-top:200px;//This creates space between the images, but the text doesn't flow between them
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只能通过使用额外的辅助元素来实现它。
看看这个小提琴: http://jsfiddle.net/kizu/BwySX/
您只需添加辅助元素宽度为零,因此它们会用其高度推动浮动元素,但由于宽度为零,文本几乎完美地在它们附近流动。
You can achieve it only by using extra helper elements.
Look at this fiddle: http://jsfiddle.net/kizu/BwySX/
You just add helper elements with zero width, so they are pushing your floaters with their height, but as they have zero width, the text flows near them almost perfectly.
不确定这是否可能。边距总是把一切都推到一边。
我将文本分成几个段落,每个段落只有一张图像。然后图像就可以漂浮在其中。
Not sure that's possible. A margin always pushes everything to the sides.
I'd divide the text into paragraphs, and have only one image per paragraph. Then the image could float inside it.