為自適應影像使用 CSS 寬度屬性


為自適應影像設定 100% 的寬度屬性。你可以嘗試執行以下程式碼以讓影像自適應

示例

線上演示

<!DOCTYPE html>
<html>
   <head>
      <meta name = "viewport" content="width=device-width, initial-scale = 1.0">
         <style>
            img {
               width: 100%;
               height: auto;
            }
         </style>
   </head>
   <body>
      <p>To check the effect, you need to resize the browser.</p>
      <img src = "https://tutorialspoint.tw/python/images/python-data-science.jpg"
         alt = "Python Data Science" width = "400" height = "300">
   </body>
</html>

更新於: 2020-6-25

87 次瀏覽

開啟你的職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.