flex 怎么使div浮动在外层

clipboard.png

请问怎么实现右下角的图标距离底部122rpx 一直悬浮在右边。使用的flex布局,我这样写不生效呢。
我的代码如下:

   <view class="flex_column"> //最外层view
     <view class="rightFlot"> 
         <view class="barrage background-feef88">
             <image src="../../static/img/barrage.png"></image>
         </view>
     </view>
  </view>
.flex_column{
  flex-direction: column;
 .rightFlot{
    justify-content: flex-end;
    .barrage{ 
        width: 106upx;
        height: 106upx;
        justify-content: center;
        border-radius: 50%;
        line-height: 106upx;
        display: fixed;
        bottom: 122upx;
        right:0;
        z-index: 999;
        image{
            width: 70upx;
            height: 40upx;
            margin-top:33rpx;
        }
    }
}

}

阅读 7.2k
4 个回答

楼上说的对,用position很简单的.

.barrage {
    position: fixed;
    right: 0;
    bottom: 122upx;
}

我看你代码中有z-index、以及调整位置的right、bottom等属性,这些属性在不设置position属性(设为relative,absolute,fixed)的时候是不生效的。

还是要用定位position,定位的元素会脱离flex布局,不会对其他兄弟元素有什么影响;

rpx,你这是小程序哇,用position:fixed吧,我之前做固定悬浮右边也是用position:fixed;

.barrage{
    position:fixed;
    bottom:122rpx;
    right:0;
}

flex 主要是用来进行一维布局的
而你要的脱离文档流应当使用 position: absolute // fixed

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题