為寬度和高度屬性新增 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>

更新於: 2020 年 6 月 23 日

532 次瀏覽

開啟你的 職業生涯

完成課程並獲得認證

開始
廣告
© . All rights reserved.