在 CSS 中, overflow屬性用於控制溢出其包含元素的內容的行為。它通常與指定的高度或寬度結合使用,以定義內容在超過指定尺寸時的行為。 overflow屬性可以採用多個值:

  1. 可見(預設):內容不被剪切,並且可能溢出內容框。

    CSS
    .example { overflow: visible; }
  2. 隱藏:溢出的內容被剪切並且不可見。

    CSS
    .example { overflow: hidden; }
  3. 捲動:向元素添加捲軸,允許使用者捲動並查看隱藏的內容。

    CSS
    .example { overflow: scroll; }
  4. auto:與scroll類似,但只有在內容溢位時才加入捲軸。

    CSS
    .example { overflow: auto; }
  5. 繼承: overflow屬性從父元素繼承其值。

    CSS
    .example { overflow: inherit; }

下面是一個簡單的範例,說明了overflow屬性的用法:

CSS
.container { width: 200px; height: 100px; overflow: scroll; } .content { width: 300px; height: 150px; background-color: lightblue; }
html
<div class="container"> <div class="content"> <!-- Content that exceeds the container dimensions --> <!-- Scrollbars will appear due to the overflow: scroll; property --> </div> </div>

在此範例中, .content div 內的內容超出了.container div 指定的尺寸,並且由於容器上的overflow: scroll;屬性,將出現捲軸。

根據您的特定佈局和設計要求調整值和屬性。