將 CSS 寬度屬性用於自適應影像


將 width 屬性設為 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.