当 div 宽度在 vmin 中时如何自动调整图像大小以适合 div

问题描述 投票:0回答:1

`我正在尝试运行以下代码,但我的图像对于我的 div 来说总是太大,所以它部分出现了

.display-box
 {
 width:80vmin;
 padding:50px 40px;
 background-image: url("paper.gif");
 background-size: cover; 
 position: absolute;
 width: 80vmin;
 height:80vmin;
 padding:50px 40px;
 top:50%;
 left:50%;
 transform: translate(-50%,-50%);
  }

我尝试使用 background-size: cover 和 background-size: contain 以及 no-repeat center center fixed; 但它没有用。`

html css
1个回答
0
投票

如果你不需要保持宽高比那么你可以使用

background-size: 100% 100%;

© www.soinside.com 2019 - 2024. All rights reserved.