将 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.com/python/images/python-data-science.jpg"
         alt = "Python Data Science" width = "400" height = "300">
   </body>
</html>

更新日期:2020 年 6 月 25 日

87 次浏览

开启你的 职业生涯

完成课程以获得认证

开始
广告
© . All rights reserved.