微信小程序开发—背景图片全屏(无白条)

错误示例

微信小程序开发过程中,为了增加界面的美观程度,可以尝试将一张图片设置为背景。在网上最主要的方法为:
index.wxml

<view class="content">
  <!--pics文件夹下的background.jpg文件-->
  <image class='background' src="/images/beijing.jpg" mode="aspectFill"></image>
  <!--页面其它部分-->
</view>

index.wxss

page{
  height:100%;
  }
.background {
  width: 100%;
  height: 100%;
  position:fixed; 
  background-size:100% 100%;
  z-index: -1;
  }

但是问题出现了,在导航栏和图片的交界处出现了一条白线,十分影响美观。
在这里插入图片描述

正确示例

所以需要再加上如下两段代码,以便于隐藏这一条白条:
index.wxml(注:此条代码必须放在最后,否则可能会把这段代码之后的view组件遮盖)

<view class='main'>
  <image src="{{url}}" mode='widthFix' >
  </image>
</view>

index.wxss

.main{
  width: 100%;
  height: 100%;
}
image{
  width:100%;
  height: 100%;
  position: absolute;
  top:0px;
  bottom:0px;
}

效果如下:
在这里插入图片描述

正确代码段

为方便摘用,整合为一下内容:
index.wxml

<view class="content">
  <!--pics文件夹下的background.jpg文件-->
  <image class='background' src="/images/beijing.jpg" mode="aspectFill"></image>
  <!--页面其它部分-->
</view>

//*************此处添加代码*************//

<view class='main'>
  <image src="{{url}}" mode='widthFix' >
  </image>
</view>

index.wxss

page{
  height:100%;
  }
.background {
  width: 100%;
  height: 100%;
  position:fixed; 
  background-size:100% 100%;
  z-index: -1;
  }
image{
  width:100%;
  height: 100%;
  position: absolute;
  top:0px;
  bottom:0px;
}
.main{
  width: 100%;
  height: 100%;
}
  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值