- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
请耐心等待...请原谅我(可能)不正确的术语:
在下面的代码中,我不明白为什么要将包含(父)div 设置为“position:relative”,以便内部的 div 相对于父 div 定位(使用“position:absolute”)。我认为为了实现这一点,子 div 将被设置为“相对”于父级。我是否理解父 div 本质上是在对内部的其他 div 说“嘿,你们现在都可以相对于我定位了!”我有点希望它能以相反的方式工作。
例如我预计文本会定位到包含 div 的“相对”位置。有人可以解释为什么它会像这里那样工作吗?谢谢。
<div id="backgroundImage">
<h2 class="titleBox">I AM A TITLE</h2>
<p class="textBox">I am a description box</p>
</div>
#backgroundImage {
position: relative;
height: 225px;
width: 300px;
background-image: url (#);
}
.titleBox {
position: absolute;
top: 15px;
left: 0;
}
.textBox {
position: absolute;
bottom: 10px;
left: 0;
}
最佳答案
documentation解释得很好,但我会总结一下。
An element with position:relative is first laid out just like any static element ... shifted according to the
top
,bottom
,left
andright
properties
position: relative
框可以相对于其父项进行调整(即使其父项是静态的)。
对于 position: absolute
,
the containing block is the nearest positioned ancestor. By “positioned” I mean an element whose position property is set to
relative
,absolute
orfixed
也就是说,position: absolute
元素上的top
、bottom
等属性是相对于最近的包含元素的position
不同于static
(包括relative
)。
也就是说position: absolute
元素仍然可以相对定位。
关于html - 我想完全掌握包含 div 的 'position: relative' 的概念,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17163333/
使用登录后,我想吐出用户名。 但是,当我尝试单击登录按钮时, 它给了我力量。 我看着logcat,但是什么也没显示。 这种编码是在说。 它将根据我在登录屏幕中输入的名称来烘烤用户名。 不会有任何密码。
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎是题外话,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或include a min
我是一名优秀的程序员,十分优秀!