【发布时间】:2021-11-18 14:37:32
【问题描述】:
我需要一个 div 宽度为 50% 的背景(从左边缘到中心)。并且背景图像在屏幕改变时不应该改变比例。现在我有了css:
.bg {
display: flex;
justify-content: center;
align-items: stretch;
flex-direction: column;
background: url(../img.png);
background-position: left;
background-size: 50vw 100%;
-webkit-background-size: 50vw 100%; /* browser support */
-moz-background-size: 50vw 100%; /* browser support */
-o-background-size: 50vw 100%; /* browser support */
background-repeat: no-repeat;
}
<div class="bg container-fluid px-0">
<div class="container-xl">
<div class="left"></div>
<div class="right"></div>
</div>
</div>
img的尺寸:1043*735
但图像在不同屏幕上会改变比例(压缩或拉伸)。有没有办法做图像“覆盖”但仍然是 div 的一半?
【问题讨论】:
-
您能提供照片的尺寸或绝对参考吗?
-
1043x735px
标签: css background-image