.first-screen-modal{  //父容器
  position: absolute;
  left: 0;
  top: 0;
  right:0;
  height: 800px;
  width: 600px;
  z-index: 100;
  margin: 100px 75px 306px 75px;
  .photo-bg{   //背景图对应的div
    background-image: url(images/rest.png);
    border-radius: 16px;
    width:100%;
    height:100%;
    background-position: center center;
    background-repeat: no-repeat;
    background-size:contain;   //关键属性
  }

 

 

background-size:contain;   //关键属性,此时会保持图像的纵横比并将图像缩放成将适合背景定位区域的最大大小。只要背景图宽高有一边达到容器的边框,就会停止放大

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐