為 width 和 height 屬性新增 CSS 過渡效果


若要為某個元素的 width 和 height 屬性新增過渡效果,可以嘗試執行以下程式碼

範例

線上演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         div {
            width: 150px;
            height: 150px;
            background: blue;
            transition: width 3s;
         }
         div:hover {
            width: 250px;
            height: 250px;
         }
      </style>
   </head>
   <body>
      <h1>Heading One</h1>
      <p>Hover over the below box to change its width and height.</p>
      <div></div>
   </body>
</html>

更新日期:23-06-2020

532 次瀏覽

開啟你的職業生涯

完成課程即獲得認證

開始
廣告