CSS位置无法正常工作

问题描述 投票:3回答:2

这是我的代码

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新手,所以正在尝试定位。我读了一些]

绝对位置元素相对于具有非静态位置的第一个父元素放置。如果找不到这样的元素,则包含块为<html>

如果正确,则This is a heading with an absolute position消息必须低于Heading for Fixed Position,因为h1是父对象,而h2是绝对对象,因此必须相对于h1定位。如果我错了,请更正。

这里是JSFiddle链接:

http://jsfiddle.net/KXmgG/

这是我的代码CSS h2 {位置:绝对;左:100px;顶部:150px; } h1 {位置:固定;顶部:...

html css positioning
2个回答
3
投票

我想向您解释定位实际上是如何工作的,有4种类型


0
投票

“绝对位置元素相对于具有非静态位置的第一个父元素放置。如果找不到这样的元素,则包含块为:”]

© www.soinside.com 2019 - 2024. All rights reserved.