为什么删除宽度 100% 时我的背景图像消失了?
Why does my background image disappear when the width is 100% deleted?
我正在创建标题,但如果我关闭“宽度:100%”,background-image 将不再出现。这有什么意义?
.img_header{
position: absolute;
background-image: url(space.jpg);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
width: 100%; /*----> example if I dismiss this property the image disappear */
z-index: -1;
height: 400px;
}
唯一给它宽度的是你的CSS。
背景图片本身不占用任何空间 space。所以如果你删除宽度,那么它就会消失,因为没有其他内容可以给元素大小。
我正在创建标题,但如果我关闭“宽度:100%”,background-image 将不再出现。这有什么意义?
.img_header{
position: absolute;
background-image: url(space.jpg);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
width: 100%; /*----> example if I dismiss this property the image disappear */
z-index: -1;
height: 400px;
}
唯一给它宽度的是你的CSS。
背景图片本身不占用任何空间 space。所以如果你删除宽度,那么它就会消失,因为没有其他内容可以给元素大小。