【问题标题】:Absolute positioned eleement by no positioned ancestor set itself by monitor no body无定位祖先的绝对定位元素由监视器无主体设置自身
【发布时间】:2017-05-25 19:53:11
【问题描述】:

绝对定位元素(输入)放置在显示器底部,没有正文。

如果我给body添加一个相对位置,输入body底部的位置!

为什么?

<body>

     <input type="button" value="click" style="position:absolute;bottom:0;" />

     <div style="height:500px;background-color:red;"></div>
     <div style="height:500px;background-color:blue;"></div>
     <div style="height:500px;background-color:green;"></div>
     <div style="height:500px;background-color:yellow;"></div>
     <div style="height:500px;background-color:pink;"></div>

</body>

【问题讨论】:

    标签: html css position absolute


    【解决方案1】:

    要使子元素绝对定位于其父元素,我们需要在父元素本身上设置它

    https://css-tricks.com/almanac/properties/p/position/

    【讨论】:

    • "如果一个绝对定位元素没有定位的祖先,它使用文档正文"
    • 嘿 @AliMottaghiPour 如果没有明确指定,任何 html 元素的默认位置都是静态的。 position: static; 不是相对的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-13
    • 1970-01-01
    • 1970-01-01
    • 2011-06-19
    • 1970-01-01
    • 1970-01-01
    • 2017-03-09
    相关资源
    最近更新 更多