这是我的代码
CSS
我刚开始学习CSS,正在尝试定位的功能。我在某处读到:
这是 JSFiddle 链接: http://jsfiddle.net/KXmgG/
CSS
h2
{
position: absolute;
left: 100px;
top: 150px;
}
h1
{
position: fixed;
top: 300px;
}
HTML
<h1>
Heading for Fixed Position
<h2>
This is a heading with an absolute position</h2>
</h1>
我刚开始学习CSS,正在尝试定位的功能。我在某处读到:
如果这是正确的,那么绝对定位元素的位置是相对于第一个具有非 static 定位属性的父元素来确定的。如果没有这样的元素,则相对于包含块即
<html>
元素进行定位:
This is a heading with an absolute position
消息必须在 Heading for Fixed Position
下面,因为 h1 是父对象,h2 作为绝对对象必须相对于 h1 进行定位。如果我错了,请纠正我。这是 JSFiddle 链接: http://jsfiddle.net/KXmgG/