📜  如何使用 CSS 更改滚动条的位置?

📅  最后修改于: 2021-09-01 02:49:34             🧑  作者: Mango

滚动条的功能可以通过使用 CSS 来控制。早些时候这是不可能的,但随着新版本的 CSS 使网页设计师成为可能。我们可以使用 CSS “::-webkit-scrollbar”属性,它负责改变滚动条的形状、颜色、大小、阴影、阴影等。但是,这里我们将使用的属性是 CSS 的方向属性,用于更改滚动条的位置。

注意:在每个示例中为滚动条添加基本的 CSS 属性以使其看起来更好。

示例 1:此示例将滚动条放置在div 元素的右侧(默认情况下)。



      

    Customize the scroll-bar
  
    

  

    

        GeeksforGeeks     

           
        
            GeeksforGeeks is a Computer Science             portal for geeks. It contains well             written, well thought and well             explained computer science and             programming articles, quizzes etc.         
    
  

输出:输出包含分区右侧的黑色滚动条。

示例 2:将滚动条放置在 div 元素的左侧。突出显示了右侧滚动条和左侧滚动条代码之间的差异



      

    Customize the scroll-bar
  
    

  

    

        GeeksforGeeks     

           
        
            GeeksforGeeks is a Computer Science             portal for geeks. It contains well             written, well thought and well             explained computer science and             programming articles, quizzes etc.         
    
  

输出:黑色滚动条显示在 div 元素的左侧。

示例 3:将滚动条置于分区底部。



      

    Customize the scroll-bar
      
    

  

    
    

        GeeksforGeeks     

           
        
            GeeksforGeeks is a Computer Science             portal for geeks. It contains well             written, well thought and well             explained computer science and             programming articles, quizzes etc.         
    
  

输出:黑色滚动条显示在 div 元素的底部。

示例 4:将滚动条放置在 div 元素的顶部。已突出显示滚动条底部位置和滚动条代码顶部位置之间的差异。



  

    Customize the scroll-bar
      
    

  

    

        GeeksforGeeks     

           
        
            GeeksforGeeks is a Computer Science             portal for geeks. It contains well             written, well thought and well             explained computer science and             programming articles, quizzes etc.         
    
  

输出:黑色滚动条显示在容器 div 元素的顶部。

注意:使用 HTML 和 CSS 还可以将网页滚动条的位置从页面右侧更改为左侧。

示例 5:将滚动条放置在整个页面的左侧



      

    Customize the scroll-bar
      
    

  

    

        GeeksforGeeks     

           
        GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.         GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.     
    
    
        GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.         GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.     
    
    
        GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.         GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.     
    
    
        GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.         GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.     
    
    
        GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.         GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.     
    
    
        GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.         GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.     
  

输出:

示例 6:突出显示了两个代码之间的差异。



      

    Customize the scroll-bar
      
    

  

    

        GeeksforGeeks     

           
        GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.         GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.     
    
    
        GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.         GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.     
    
    
        GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.         GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.     
    
    
        GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.         GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.     
    
    
        GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.         GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.     
    
    
        GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.         GeeksforGeeks is a Computer Science         portal for geeks. It contains well         written, well thought and well         explained computer science and         programming articles, quizzes etc.     
  

输出: