CSS 数据类型 - <overflow>



CSS 数据类型<overflow>表示用于overflow属性和详细属性overflow-blockoverflow-inlineoverflow-xoverflow-y的关键字值。

可能的值

<overflow>数据类型使用下面列出的值之一指定。

  • visible:内容不被裁剪。它延伸到盒子之外。

  • hidden:内容被裁剪,溢出部分隐藏。

  • clip:内容在元素的溢出剪切边缘处被裁剪。

  • scroll:内容被裁剪,并添加滚动条以允许用户滚动查看隐藏的内容。

  • auto:浏览器在内容溢出时自动添加滚动条。

语法

<overflow> = visible | hidden | clip | scroll | auto

CSS <overflow> - 基本示例

在提供的示例中,CSS 数据类型<overflow>应用于<pre>元素以调节溢出内容的行为。

每个<pre>元素的内容决定了当它超过其定义的尺寸时,基于设置给overflow的不同值,将如何表现。

<html>
<head>
<style>
   pre {
      border: 2px solid black;
      margin-bottom: 3em;     
   }
   ::before {
      font-size: 15px;
      font-weight: bold;
      color: white;
      background: darkorchid;
      display: inline-block;
      width: 100%;
      padding: 5px 10px;
      box-sizing: border-box;
   }
   pre {
      block-size: 110px;
      inline-size: 250px;
   }
   pre:nth-of-type(1) {
      overflow: hidden;
   }
   pre:nth-of-type(1)::before {
      content: "hidden: ";
   }
   pre:nth-of-type(2) {
      overflow: clip;
   overflow-clip-margin: 1em;
   }
   pre:nth-of-type(2)::before {
      content: "clip: ";
   }
   pre:nth-of-type(3) {
      overflow: scroll;
   }
   pre:nth-of-type(3)::before {
      content: "scroll: ";
   }
   pre:nth-of-type(4) {
      overflow: auto;
   }
   pre:nth-of-type(4)::before {
      content: "auto: ";
   }
   pre:nth-of-type(5) {
      overflow: clip;
      overflow: overlay;
      overflow-clip-margin: 3em;
   }
   pre:nth-of-type(5)::before {
      content: "overlay (or clip if not supported): ";
   }
   pre:nth-of-type(6) {
      overflow: visible;
   }
   pre:nth-of-type(6)::before {
      content: "visible: ";
   }
</style>
</head>
<body>
<pre> 
Some say the world will end in fire,
Some say in ice.
From what I've tasted of desire
I hold with those who favour fire.
But if it had to perish twice,
I think I know enough of hate
To say that for destruction ice
Is also great
And would suffice.
<b>-Robert Frost</b>
</pre>
<pre> 
Some say the world will end in fire,
Some say in ice.
From what I've tasted of desire
I hold with those who favour fire.
But if it had to perish twice,
I think I know enough of hate
To say that for destruction ice
Is also great
And would suffice.
<b>-Robert Frost</b>
</pre>
<pre> 
Some say the world will end in fire,
Some say in ice.
From what I've tasted of desire
I hold with those who favour fire.
But if it had to perish twice,
I think I know enough of hate
To say that for destruction ice
Is also great
And would suffice.
<b>-Robert Frost</b>
</pre>
<pre> 
Some say the world will end in fire,
Some say in ice.
From what I've tasted of desire
I hold with those who favour fire.
But if it had to perish twice,
I think I know enough of hate
To say that for destruction ice
Is also great
And would suffice.
<b>-Robert Frost</b>
</pre>
<pre> 
Some say the world will end in fire,
Some say in ice.
From what I've tasted of desire
I hold with those who favour fire.
But if it had to perish twice,
I think I know enough of hate
To say that for destruction ice
Is also great
And would suffice.
<b>-Robert Frost</b>
</pre>
<pre> 
Some say the world will end in fire,
Some say in ice.
From what I've tasted of desire
I hold with those who favour fire.
But if it had to perish twice,
I think I know enough of hate
To say that for destruction ice
Is also great
And would suffice.
<b>-Robert Frost</b>
</pre>
</body>
</html>
广告