css實現在一定區域內垂直上下滾動及去除滾動條


 

 

 

簡單寫下樣式:

  <div class="subject-cont">
    <div class="subject-block">
      <div v-for='(item, index) in ["語文", "數學", "英語", "物理", "化學", "生物", "體育"]' :key="index">{{ item }}</div>
    </div>
  </div>

 

css樣式:

  .subject-block {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    white-space: nowrap;
    div {
      width: 100%;
      height: 30px;
      line-height: 30px;
      text-align: center;
      font-size: 15px;
      color: #9f9fa0;
      border-bottom: 0.5px solid #ddd;
    }

    div:last-child {
      border-bottom: 0;
    }
  }
  // 去除滾動條
  .subject-block::-webkit-scrollbar {
    width: 0px;
  }

 

 

去除滾動條,可以使用 ::-webkit-scrollbar 來實現

 

如果是實現左右滾動,在  ::-webkit-scrollbar 里改成height就可以啦

 

例1:左右滾動

在左右滾動的時候,配合微信小程序中scroll-view,可能會遇到上下不齊,如下圖所示:

 

 

 這個時候,只需在item盒子上添加 上下對齊即可。

vertical-align: top;

 


免責聲明!

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



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