How to Set Responsive Image's Max Width (Bootstrap 4)

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

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

Responsive Image with Max-height & Max-width

You should add the width restriction to the outer element instead of the image. The outer element will not size over your max-width and max-height, but the image will always be 100% in width. This way your image will be responsive.

html

 <div class="kalim"><img src=""></div>

css

.kalim {display: inline-block; max-width: 800px; max-height: 800px;}

.kalim img {max-width: 100%; height:auto;}

How do I make an image's height responsive in a Bootstrap 4 column so that an embedded video in an adjacent column is not affected?

I found that if I use Bootstrap's embed-responsive class for the first column (containing the image) and wrap the image in a <div> then the embedded video in the second column behaves properly.

For some reason this doesn't work with the anchor around the placeholder image I used in the code in my question above. So I've provided my updated code below with a reference to a local image.

<html lang="en">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-3 embed-responsive border">
<div class="embed-responsive-item justify-content-end d-flex ">
<img class="mt-auto" style="height: 100%;" src="img/local_image.jpg">
</div>
</div>
<div class="col-6 border embed-responsive embed-responsive-16by9" id="vid">
<iframe class="embed-responsive-item" src="https://www.youtube.com/embed/kyJUQuaECrg" allowfullscreen></iframe>
</div>
<div class="col-3 border d-flex">
<span class="mt-auto">Some Text</span>
</div>
</div>
</div>
</body>
</html>

In css setting max-width for small images how to make width NOT bigger its original size?

Wrap the img tag in a div tag and set the max-width for the div tag to be 250px and the max-width for the img tag to be 100%.

<div style="max-width: 250px;">
<img style="max-width: 100%" src="yourImage.jpg">
</div>

No img-responsive in Bootstrap 4

From the Bootstrap 4 documentation:

Images in Bootstrap are made responsive with .img-fluid. max-width: 100%; and height: auto; are applied to the image so that it scales with the parent element.



Related Topics



Leave a reply



Submit