微信小程序scroll-view橫向滾動

官方文檔給的代碼複製下來發現沒法滾動,沒反應,使用css設置浮動屬性也無效css

 

官方沒有給出css代碼,橫向須要設置兩個css屬性才行:spa

white-space: nowrap;   ----規定段落中的文本不進行換行
display: inline-block; ----應用此特性的元素呈現爲內聯對象,周圍元素保持在同一行,但能夠設置寬度和高度地塊元素的屬性
.bc_green {background: green;width:100px; height: 100px;}
.bc_red {background: red;width:100px; height: 100px;}
.bc_blue {background: blue;width:100px; height: 100px;}
.scroll-view_H{
  width: 100%;
  white-space: nowrap; 
}
.scroll-view-item_H{
  width: 200px;
  height: 100px;
  display: inline-block;
}

 

如今咱們只要橫向滾動的代碼出來在加上上面的css就能夠橫向滾動啦code

<view class="section">
  <view class="section__title">horizontal scroll</view>
  <scroll-view class="scroll-view_H" scroll-x >
    <view id="green" class="scroll-view-item_H bc_green"></view>
    <view id="red"  class="scroll-view-item_H bc_red"></view>
    <view id="blue" class="scroll-view-item_H bc_blue"></view>
  </scroll-view>
</view>
相關文章
相關標籤/搜索