Answer the question
In order to leave comments, you need to log in
How to style an image with unknown proportions?
If, say, you need to arrange an arbitrary number of pictures with proportions unknown in advance, and moreover, the proportions will be guaranteed to be different. And the grid is naturally with fixed cell sizes.
How can I make the images display without distorting the proportions? And at the same time, observe the rule that the tag must have the attributes of width and height.
I myself suffered here for a couple of days, but it only works fine if the width and height attributes are not specified, but set in CSS max-width , max-height. But here it turns out that the page is not valid.
Answer the question
In order to leave comments, you need to log in
attributes-attributes, but no one bothers to set the width and height in styles
.img {
width: 100%;
max-width: 100%;
height: auto;
}
put the pictures in a fixed width div
and the pictures
img{
max-width:100%;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question