📜  使用 CSS 使 div 可水平滚动

📅  最后修改于: 2021-11-07 08:19:31             🧑  作者: Mango

使用 CSS 溢出属性可以轻松使 div 水平滚动。溢出属性有不同的值。

例如溢出:自动;和轴隐藏程序,如溢出-x: auto;。它只会制作一个水平滚动条。
对于水平滚动条,使用 x 和 y 轴。设置溢出-y:隐藏;溢出-x:自动;这将自动隐藏垂直滚动条并仅显示水平滚动条。空白:nowrap;属性用于将文本包装在一行中。此处滚动 div 将可水平滚动。

示例 1:

HTML


    
        
            Making a div horizontally 
            scrollable using CSS  
        
        
    
    
      
      

          GeeksforGeeks       

      

        Making a div horizontally          scrollable using CSS       

      
          It is a good platform to learn programming.           It is an educational website. Prepare for            the Recruitment drive of product based companies           like Microsoft, Amazon, Adobe etc with a free            online placement preparation course. The           course focuses on various MCQ's & Coding question            likely to be asked in the interviews & make your            upcoming placement season efficient and successful.           Also, any geeks can help other geeks by writing            articles on the           GeeksforGeeks, publishing articles follow few steps           that are Articles that need little modification or            improvement from reviewers are published first.           To quickly get your articles reviewed, please refer           existing articles, their           formatting style, coding style, and try to make you            are close to them. In case you are a beginner, you            may refer Guidelines to write an Article       
      
    


HTML


    
        
            Making a div horizontally 
            scrollable using CSS  
        
        
    
    
      
      

          GeeksforGeeks       

      

        Making a div horizontally          scrollable using CSS       

      
          It is a good platform to learn programming.           It is an educational website. Prepare for            the Recruitment drive of product based companies           like Microsoft, Amazon, Adobe etc with a free            online placement preparation course. The           course focuses on various MCQ's & Coding question            likely to be asked in the interviews & make your            upcoming placement season efficient and successful.           Also, any geeks can help other geeks by writing            articles on the           GeeksforGeeks, publishing articles follow few steps           that are Articles that need little modification or            improvement from reviewers are published first.           To quickly get your articles reviewed, please refer           existing articles, their           formatting style, coding style, and try to make you            are close to them. In case you are a beginner, you            may refer Guidelines to write an Article       
      
    


输出:

示例 2:在本示例中,使用 auto 代替 overflow-y: hidden;和溢出-x:自动;使 div 可水平滚动。

HTML



    
        
            Making a div horizontally 
            scrollable using CSS  
        
        
    
    
      
      

          GeeksforGeeks       

      

        Making a div horizontally          scrollable using CSS       

      
          It is a good platform to learn programming.           It is an educational website. Prepare for            the Recruitment drive of product based companies           like Microsoft, Amazon, Adobe etc with a free            online placement preparation course. The           course focuses on various MCQ's & Coding question            likely to be asked in the interviews & make your            upcoming placement season efficient and successful.           Also, any geeks can help other geeks by writing            articles on the           GeeksforGeeks, publishing articles follow few steps           that are Articles that need little modification or            improvement from reviewers are published first.           To quickly get your articles reviewed, please refer           existing articles, their           formatting style, coding style, and try to make you            are close to them. In case you are a beginner, you            may refer Guidelines to write an Article       
      
    

输出:

HTML 是网页的基础,用于通过构建网站和 Web 应用程序进行网页开发。您可以按照此 HTML 教程和 HTML 示例从头开始学习 HTML。

CSS 是网页的基础,用于通过样式化网站和 Web 应用程序进行网页开发。您可以按照此 CSS 教程和 CSS 示例从头开始学习 CSS。