【发布时间】:2020-12-18 13:05:22
【问题描述】:
我正在创建一个标题,但如果我关闭“宽度:100%”,则背景图像不再出现。这有什么意义?
.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;
}
【问题讨论】:
-
@MisterJojo width 的默认值不是 0,而是 auto 和 auto 的 position:absolute 是收缩以适应,如果没有内容,计算的值将是 0
-
如果你删除
width: 100%;,“默认值”将是喜欢width: 0;
标签: html css image background width