CSS:在一个绝对定位的div后面有一个div [英] CSS: have a div after an absolute positioned div
问题描述
我想知道如何做到这一点,我目前的标记如下:
I was wondering how to do this, my current mark up is as follows:
<div id="playArea" style="position: relative;">
<div id="widget1" class="widget" style="position: absolute; left: 295px; top: -1px; width: 313px; height: 269px;">Hello</div>
<div id="widget2" class="widget" style="position: absolute; left: 63px; top: 35px; width: 80px; height: 42px;">World</div>
<div style="position: absolute; left: 534px; top: 329px; width: 183px; height: 251px;">Bye</div>
</div>
现在,如果我在最后一个< / div> ;
, p
标签的内容不会出现在浏览器中的所有div下。
任何想法如何我可以做到这一点?
Now, if I create a paragraph tag after the last </div>
, the content of the p
tag is not appearing under all of these div's in the browser.
Any ideas how i can do this?
感谢伙伴
推荐答案
如果您使用绝对定位你不知道你的定位的高度,这是一个问题,HTML不是很好解决。我已经看过(也可能写的)hacks,其中JavaScript用于定位基于另一个的 offsetHeight
的元素。
If you're using absolute positioning but you don't know the height of what you're positioning, that is a problem that HTML isn't very good at solving. I have seen (and probably written) hacks where JavaScript is used to position an element based on the offsetHeight
of another.
但是你最好使用CSS float
属性,而不是绝对定位。 float
和 clear
非常适合用于定位您喜欢的内容,而不会牺牲自动页面流。
But you might be better off using the CSS float
property instead of absolute positioning. float
and clear
are pretty good for positioning things like you want, without sacrificing automatic page flow.
这篇关于CSS:在一个绝对定位的div后面有一个div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!