CSS - 溢出


描述

溢出属性确定应如何处理溢出其元素内容区域的内容

可能的值

  • 可见- 应显示溢出的内容。

  • 隐藏- 不应显示溢出的内容。

  • 滚动- 不应显示溢出的内容,但用户代理应提供某种访问隐藏内容的方法(例如,一组滚动条)。

  • auto - 由该值引起的Behave取决于浏览器。

适用于

所有 HTML 元素。

DOM语法

object.style.overflow = "scroll";

例子

这是例子 -

<html>
   <head>
      <style type = "text/css">
         .scroll {
            display:block;
            border: 1px solid red;
            padding:5px;
            margin-top:5px;
            width:300px;
            height:50px;
            overflow:scroll;
         }
         .auto {
            display:block;
            border: 1px solid red;
            padding:5px;
            margin-top:5px;
            width:300px;
            height:50px;
            overflow:auto;
         }
      </style>
   </head>

   <body>
   
      <p>Example of scroll value:</p>
      
      <div class = "scroll">
         I am going to keep lot of content here just to show you how 
         scrollbars works if there is an overflow in an element box. 
         This provides your horizontal as well as vertical scrollbars.
      </div>
      <br />
      
      <p>Example of auto value:</p>
      
      <div class = "auto">
         I am going to keep lot of content here just to show you how 
         scrollbars works if there is an overflow in an element box. 
         This provides your horizontal as well as vertical scrollbars.
      </div>
      
   </body>
</html> 

这将产生以下结果 -