我正在研究一些期刊问题的图形表示。我需要的是在其他 DIV 中使用简单的 DIV(或其他)显示文本 block ,完全按照它们在问题页面上的组织方式。为此,我需要将 DIV 元素的坐标设置为精确数字,但与父 DIV 相关。有没有办法通过使用 css 或 js 来做到这一点?
最佳答案
如果您将外部 div 设置为 position: relative
,则可以将内部 div 设置为 position: absolute
并将其 top、left、right 和 bottom 属性设置为你需要的像素。例如。
.outer {
position: relative;
}
.inner {
position: absolute;
top: 10px; //your coordinate
left: 5px; //your coordinate
}
<div class="outer">
<div class="inner">Your content</div>
</div>
否则,您可以简单地在内部元素上使用填充。
关于javascript - 用js、css、html设置DIV中元素的坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42676737/