Images are created in a loop with:
-
You can do this :
- wrap the image in a container with
padding-bottom:100%; overflow:hidden; position:relative
- position the image absolutely inside that container.
FIDDLE
Explanation :
Padding top/bottom (like margin top/bottom) is calculated according to the width of parent element.As the .image div has the same width as its parent, setting padding-bottom:100%; give it the same height as its width so it is square (its content needs to be absolutely positioned or floated so it doesn't change the parent's size).
HTML:
CSS:
.image{
position:relative;
overflow:hidden;
padding-bottom:100%;
}
.image img{
position:absolute;
}
- 热议问题