简体   繁体   English

Javascript \\ jQuery:是否可以使用x和y坐标覆盖元素?

[英]Javascript\jQuery: is it possible to overlay elements using x and y coordinates?

可以通过搜索,找到父元素然后添加到它们之前而不是绝对地定位(我必须这样做,不要问为什么)元素在其他元素上,可以通过坐标找到某些元素的位置,然后简单地调整窗口大小时重新计算替换的坐标?

You can do this by subtracting your margins. 您可以通过减去边距来实现。

If you were to append a child into a container that already contained a child just subtract the same height as the existing child from the new childs margin. 如果要将孩子添加到已经包含孩子的容器中,只需从新孩子的边距中减去与现有孩子相同的高度。

Notice the margin-top:-100px below 请注意margin-top:-100px以下

  <div id="parentContainer" style="width:100px;height:100px;float:left">

        <div id="child1" style="width:100px;height:100px;float:left;background-color:red">

        </div>

        <div id="child2" style="width:100px;height:100px;float:left;background-color:blue;
                                margin-top:-100px">
        </div>

  </div>

If you prepend the do a margin-bottom:-100px 如果您在前面加上一个下边距:-100px

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM