如何设置响应式图片最大宽度 (Bootstrap 4)?

How to set responsive image's max width (Bootstrap 4)?

问题:

背景:

max-width: 100%; and height: auto; are applied to the image so that it scales with the parent element (https://getbootstrap.com/docs/4.1/content/images/)

我的情况:

希望这很清楚;我试图在这里寻找类似的问题,但没有成功。干杯!

.img-max {
  max-width: 500px
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<p class="alert-primary p-3">
  I can set the max-width of the image... but then it stops being responsive.
</p>
  



<div class="container">
  <div class="img-max">
  <img  class=" mx-auto d-block mb-2 float-md-left mr-md-4 img-thumbnail"  src="https://images.pexels.com/photos/2422/sky-earth-galaxy-universe.jpg">
  </div>
  <p>
    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Labore ipsa ea dolorem mollitia repudiandae odit dolore quod et voluptatem asperiores odio quam ipsam placeat nisi quo voluptate, laborum provident earum?
  </p>
</div>

你的答案在这里

.img-max {
  max-width: 500px;
  width:100%;
}

并使用图像中的 class。

我已经编辑了你的fiddle。请参考link

jsfiddle.net/saravanan7944/ygamjz7s/1