I'm attempting to make a 2x2 grid with each cell 300x300px. Each cel开发者_运维技巧l has an image, which fades in and out, reloaded using AJAX ( jQuery to be precise) - creating a 4 image gallery over ajax. All images are simply dumped into a folder, so there is no defined height or width of them.
Is there any way by which I can have the fill the space? eg, a portrait shaped image would resize to height=300, while its width might be smaller... and similarly for a landscape image ( width=300 with smaller height)? I'm trying to eliminate any resizing of the cells, because it is rather horrible to watch.
I"ll leave centering these vertically and horizontally till later. Thanks for any help!
UPDATE: I've pastebin'ed the current code http://pastebin.com/Hz4fJk9p
Use max-height:300px;
and max-width:300px;
, assuming your image is not smaller than 300px in both dimensions to begin with.
Even if it's not CSS, I've found some interesting libraries for doing image resizing to fit the container:
- http://plugins.jquery.com/project/myimgscale
- http://code.google.com/p/jquery-imagefit-plugin/
精彩评论