【发布时间】:2019-03-15 10:31:09
【问题描述】:
我有一个带有背景图片的 div 部分。 div 部分的宽度可变,但高度固定。 背景图像始终与 div 部分相同,位于底部中心。
footer{
position: absolute;
bottom: -20px;
left: 0;
right: 0;
height: 300px;
width: 100%;
color: #fff;
background-color: #7f7f7f;
}
footer::before{
content: "";
position: absolute;
top: 0px;
height: 100%;
width: 100%;
background-image: url("./img.png");
background-repeat: no-repeat;
background-size: 100% auto;
background-position: bottom center;
opacity: 0.4;
}
如果现在 div 部分变为宽度,则背景图像变为高度并在顶部被剪切。 如果图像变为高度,我想将位置更改为顶部中心,因此剪切图像的底部。有没有办法实现这种效果?
【问题讨论】:
-
请也分享您的 HTML 代码。
-
@AndrzejZiółek : HTML 代码只有 标签。
-
目前我用css代码中的@media解决了这个问题。但也许有更好的解决方案。
标签: css background-image positioning