html - How to create square image thumbnails using only CSS -
on webpage rendering collection of images. images portrait orientation, landscape, larger desired render size.
i want display these images in gallery of neat, uniformly sized, square thumbnails.
how can using css?
i avoid javascript library if possible. don't need select part of image display, central-ish square area.
i've seen question asked elsewhere, have not yet found answer seems work orientations (e.g., portraits may correctly cropped/resized, landscapes not).
you still use server side technology resize image via curl; however, neither here nor there. 1 thing understand, css not programming language, in, cannot make decisions or real math, can't make dynamic decisions css.
that being said, create divs gallery, , use css set background image desired image. in css3 there property called background-size
. can set size in pixels manually, not maintain aspect ratio way, awful. setting background-size: cover
scale image fills background area while cutting off excess. setting background-size: contain
scale image maintains original aspect ratio , fills background without cutting off image. here little code kind of explains how use it. jsfiddle
edit: forgot mention solution work in ie9+ (should work fine in ff, chrome , safari)
Comments
Post a Comment