为自适应图像使用 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.com/python/images/python-data-science.jpg"
         alt = "Python Data Science" width = "400" height = "300">
   </body>
</html>

更新于: 2020-6-25

87 次浏览

开启你的职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.