微信小程序如何才能拉伸背景图,以适合页面大小?

直接上代码:

WXML:

<view class="container">
  ...
</view>

WXSS:

.container {
  position: relative;
}
.container::after {              
  content: "";                   
  background: url(https://example.com/bg.jpg) no-repeat center center;                         
  background-size: cover;        
  opacity: 0.4;                  
  top: 0;                        
  bottom: 0;                     
  left: 0;                       
  right: 0;                      
  position: absolute;            
  z-index: -1;                   
}

猜你喜欢

转载自blog.csdn.net/henryhu712/article/details/87899757