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

后端 未结 2 1097
醉话见心
醉话见心 2021-01-04 12:12

Question:

  • How do you set the max-width of an image in Bootstrap 4 while retaining the image\'s responsiveness?

Backgrou

相关标签:
2条回答
  • 2021-01-04 12:52

    .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>

    0 讨论(0)
  • 2021-01-04 12:55

    Your answer is here

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

    and use the class in the image.

    I have edited your fiddle. Please refer the link

    jsfiddle.net/saravanan7944/ygamjz7s/1

    0 讨论(0)
提交回复
热议问题