Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Everytime i change the image img is resizing

I want to make the img tag stricted. In my example, everytime i change the image, size of it also changes.

Here is an example:
enter image description here

.cat {
 width:200px
}
img {
 max-width: 100%;
 height: auto; 
}
<!DOCTYPE html>
<html>
<head>
<title>HTML, CSS and JavaScript demo</title>
</head>
<body>
<div class="cat">
    <img src="https://loremflickr.com/400/400" />
</div>
</body>
</html>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Your doing max-width:100% and height:auto which is letting it go to its default size if you want to make them the same size do the same width as the cat and the same width as the img:

.cat {
 width:200px;
height:200px;
}
img {
 width:200px;
height: 200px;
}

And at that point you don’t need the .cat because they are the same now so:

img {
 width:200px;
height: 200px;
}

You can remove the div with the class cat now since it’s not needed.
And here’s the finished code:

img {
 width:200px;
height: 200px;
}
<!DOCTYPE html>
<html>
<head>
<title>HTML, CSS and JavaScript demo</title>
</head>
<body>
<img src="https://loremflickr.com/400/400" />
</body>
</html>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading