位置:首页 » 文章/教程分享 » 小程序底部按钮固定的方法

如果我们需要在小程序的底部使用按钮,并且固定,用position : fixed;,可以实现。

wxml部分

<view class='bottom_view'>
    <button class='bottom_btn'>
        按钮
    </button>
</view>


wxss部分

.bottom_view{
    width: 100%;
    position: fixed;
    bottom: 30rpx;
}
.bottom_btn{
    margin-top: 30rpx;
    width: 450rpx;
    background: #14a1fd;
    color: #fff;
    border-radius: 70rpx;
}


bottom设置为0也可以,但是为了用户体验可以设置高一点。