正文未覆盖文档高度


<html>
<body>
    <img id='imgTest' src='https://www.google.com/images/srpr/logo11w.png'>
</body>
</html>

.css

html{
    height:100%;
    background:blue;
}
body{
    height:100%;
    background:yellow;
}
#imgTest{
    position:absolute;
    height:700px;
    width:200px;
    top:14px;
    left:25px;
}

我需要身体覆盖整个文档高度,并保持imgTest绝对位置。

这里是小提琴

绝对定位元素的标准问题。为了确保周围的body元素具有正确的大小,您需要指定它:

body{
    height:100%;
    background:yellow;
    margin: 0;
    min-height: 714px; /* height of image + top of image */
}

请参阅更新的小提琴。

你应该添加

 margin:0

到正文 CSS

最新更新