html - 绝对定位的 child 忽略了相对 parent

标签 html css css-position

我知道那里有很多关于定位的问题,包括关于相对父级内的绝对定位。

我已经阅读了很多此类问题,并找到了有关 css-tricks ( Absolute positioning inside relative parent) 的信息链接。全部排查失败后,我求助于你;)

This JSFiddle包含我认为是正确的,但显然不是。 为什么父 div 的子元素相对于 body 而不是 div 定位?

代码:

<div id="editorWrapper" style="posotion: relative; width:751px; height:250px; margin-left: 20px; margin-top: 20px; border: 1px solid blue;">
    <a class="lnk" href="http://www.google.be" style="display: inline-block; position:absolute; left: 1%; top: 1%; padding: 5% 5%;"></a>
    <a class="lnk" href="http://www.google.be" style="display: inline-block; position:absolute; left: 80%; top: 80%; padding: 10% 10%;"></a>
    <div style="position: absolute; padding: 10px; left: 60%; top: 60%; background-color: red;" />
</div>

编辑 答案只是一个错字。 posotion 应该在父 div 中的位置。 供将来引用:这种定位方法确实有效:)

谢谢 golang !

最佳答案

请注意:您在div#editorWrapper 的style 属性中写了posotion: relative。它应该是 position: relative 而不是。

Fixed Fiddle

关于html - 绝对定位的 child 忽略了相对 parent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22608155/

相关文章:

html - 使用 XPATH 获取 HTML 标签的类名

jquery - plax.js 仅在重新加载时有效

html - 将最大宽度应用于相对定位的 Div 中的固定位置的 Div?

css - 如何将未知宽度的绝对定位内容居中?

HTML 表格设计。哪个更好 :A large number of rows in a single table or large number of table with few rows each

html 正文不是屏幕的全尺寸

html - CSS 动画不工作(弹跳)

javascript - 使用 z-index 堆叠 XHTML 元素

javascript - For 循环中的 setTimeout 问题

html - 如何完善定位代码?