哪个属性用于告诉浏览器当框的内容大于框本身时该如何处理?

cssweb developmentfront end technology更新于 2024/9/9 6:04:17

CSS 提供了一个名为 overflow的属性,该属性用于告诉浏览器当框的内容大于框本身时该如何处理。此属性可以采用以下值之一 −

值
描述
visible
允许内容溢出其包含元素的边框。
hidden
嵌套元素的内容在包含元素的边框处被截断,并且没有滚动条可见。
滚动
包含元素的大小不变,但会添加滚动条,以便用户滚动查看内容。
自动
目的与滚动相同,但仅当内容溢出时才会显示滚动条。                                                                   

示例

您可以尝试运行以下代码来实现 overflow属性 −

<html>
   <head>
   </head>
   <style>
      .scroll{
         display:block;
         border: 2px solid green;
         padding:10px;
         margin-top:10px;
         width:300px;
         height:50px;
         overflow:scroll;
      }
      .auto{
         display:block;
         border: 2px solid green;
         padding:10px;
         margin-top:10px;
         width:300px;
         height:50px;
         overflow:auto;
      }
   </style>
   <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>

相关文章


有用资源