position: fixed 撞見 display:flex


position:flexd;與display:flex;不能在同一標簽元素下使用。因為固定定位會使得彈性布局失效。

解決方法:在彈性布局display:flex;外包裹一層view。如下:

index.wxml

<!-- 包裹層 -->
<view class="flex">
    <!-- 彈性布局層 -->
    <view class="bg">
        <view class="nav">
            <scroll-view scroll-x="true" enable-flex="true">
                <view class="scroll-view_H">
                    <view><view class="{{flag==0?'select':'normal'}}" id="0" bindtap="switchNav">專享</view></view>
                    <view><view class="{{flag==1?'select':'normal'}}" id="1" bindtap="switchNav">視頻</view></view>
                    <view><view class="{{flag==2?'select':'normal'}}" id="2" bindtap="switchNav">糗聞</view></view>
                    <view><view class="{{flag==3?'select':'normal'}}" id="3" bindtap="switchNav">純文</view></view>
                    <view><view class="{{flag==4?'select':'normal'}}" id="4" bindtap="switchNav">純圖</view></view>
                    <view><view class="{{flag==5?'select':'normal'}}" id="5" bindtap="switchNav">精華</view></view>
                    <view><view class="{{flag==6?'select':'normal'}}" id="6" bindtap="switchNav">趣聞</view></view>
                </view>
            </scroll-view>
        </view>
        <view class="opr"></view>
        <view class="add">+</view>
    </view>
</view>

 

index.wxss

/**index.wxss**/
.flex{
    width: 100%;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 999; #這里也很關鍵,z-index設置的值越大,則顯示在最上層。
}
.bg{
    display: flex;
    flex-direction: row;
    width: 100%;
    height: 50px;
    background-color: #FFBA1E;
    color: #fff;
    align-items: center;
}
.nav{
    width: 70%;
    height: 40px;
}
.scroll-view_H{
    display: flex;
    flex-direction: row;
    margin-left: 10px;
    height: 40px;
}
.opr{
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 13px;
    text-align: center;
    color: #FFBA1E;
    background-color: #fff;
    font-weight: bold;
    margin-left: 10px;
}
.add{
    width: 20%;
    height: 50px;
    line-height: 50px;
    text-align: right;
    margin-right: 10px;
    font-size: 50px;
}
.normal{
    font-size: 14px;
    width: 40px;
    height: 40px;
    line-height: 40px;
    padding-left: 10px;
    padding-right: 10px;
}
.select{
   width: 40px;
   height: 40px;
   line-height: 40px;
   font-size: 14px;
   font-weight: bold;
   padding-left: 20px;
   padding-right: 20px; 
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM