相对定位元素而不占用文档流中的空间 [英] Relatively position an element without it taking up space in document flow

查看:403
本文介绍了相对定位元素而不占用文档流中的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

如何相对定位一个元素,并且不占用文档流中的空间? 试图做绝对定位的声音。另一方面,您可以通过创建零宽度,零高度,相对定位的元素,基本上仅为了创建位置的参考点的目的而创建伪相对元素,并且绝对定位元素

 < div style =position:relative; width:0; height:0> 
< div style =position:absolute; left:100px; top:100px>
我100px偏移从我应该是,从顶部和左边。
< / div>
< / div>


How can I relatively position an element, and have it not take up space in the document flow?

解决方案

What you're trying to do sounds like absolute positioning. On the other hand, you can, however, make a pseudo-relative element, by creating a zero-width, zero-height, relatively positioned element, essentially solely for the purpose of creating a reference point for position, and an absolutely positioned element within that:

<div style="position: relative; width: 0; height: 0">
    <div style="position: absolute; left: 100px; top: 100px">
        Hi there, I'm 100px offset from where I ought to be, from the top and left.
    </div>
</div>

这篇关于相对定位元素而不占用文档流中的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆