Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

How do you auto-resize a large image so that it will fit into a smaller width div container whilst maintaining its width:height ratio?

1 Answer

0 votes
by (106k points)

To auto-resize an image to fit a 'div' container you can use the below-mentioned piece of code:-

max-width:100%;

max-height:100%;

If you want to specify a width only do height: auto;.

See the example below:-

img {

max-width: 100%; 

max-height: 100%;

}

.portrait { 

height: 80px;

width: 30px;

}

.landscape { 

height: 30px;

width: 80px;

}

.square {

height: 75px;

width: 75px;

} 

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...