为响应式图像使用 CSS max-width 属性

cssweb developmentfront end technology更新于 2024/8/25 23:40:17

您可以尝试运行以下代码来实现响应式图像的 max-width 属性

示例

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

相关文章


有用资源