當一個元素的內容可能大於分配給它的空間量時,應該怎麼做?


使用 CSS 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">
            This is Demo Content. This is Demo Content. This is Demo Content.
            This is Demo Content. This is Demo Content. This is Demo Content.
            This is Demo Content. This is Demo Content. This is Demo Content.
            This is Demo Content. This is Demo Content. This is Demo Content.
         </div>
      <br />
   </body>
</html>

更新日期:2020 年 3 月 4 日

68 次瀏覽

開啟你的 職業生涯

完成課程認證

開始
廣告