AI编程助手
AI免费问答

微信小程序背景图片显示不出来

  2020-03-26 15:55   8009浏览 原创

开发小程序的时候,设置页面的背景,用到css代码:

.page__bd{
    width: 100%;
    height: 220px;
    background: url('../../assets/img/images.jpg') no-repeat;
    background-size: 100% 100%;
}

在调试工具上是显示的,但是扫面上传到手机上却显示不出来。

这是由于:background-image 只能用网络url或者base64图片编码 , 本地图片只能用 image标签src属性才行。当然 image标签src属性也可以使用网络url或者base64图片编码。

解决方法:

下面通过 image 标签src属性设置,实现背景图显示

界面结构:

<view>
    <image></image>
    <view>
        <view>
            <image></image>
        </view>
    </view></view>

wxss样式:  

.set-background {
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 150px;
}
.set-background-avatar {
    width: 220px;
    height: 150px;
}
.background-content {
    position: absolute;
    z-index: 1;
}
.background-image {
    width: 225px;
    height: 150px;
    opacity: 0.8;
}
.post-specific-image {
    width: 215px;
    height: 150px;
    vertical-align: middle;
}

推荐:《小程序开发教程

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。