我有以下的HTML和CSS。如果我将位置属性从绝对位置改变为相对位置,则div.raw似乎在html布局中流动,并且背景图像不会掩盖所有内容。如果我不这样做,那么它的确如此。为什么是这样?为什么从相对位置改变绝对位置会改变背景图像的大小?
HTML:
<h1 class="push">Hello World</h1>
<div class="container">
Some text
<div class="raw"></div>
</div>
CSS:
.push {
margin-bottom: 50px;
margin-top: 50px;
}
.container {
margin-top: 50px;
width: 500px;
height: 500px;
margin-bottom: 50px;
}
.raw {
border: 1px solid black;
position: absolute;
top: 0;
left: 0;
background-size: auto;
background-image: url("http://st-im.kinopoisk.ru/im/wallpaper/2/3/0/kinopoisk.ru-True-Detective-2300505--w--1280.jpg");
//background-repeat: no-repeat;
overflow: hidden;
width: 50%;
height: 100%;}