I've created a two-column grid of images, which works fine with all-landscape images: Link. However, I've added a portrait image that throws off the layout, so I'd like to be able to "crop" the image so that the height matches the others'. I tried using a negative margin, but it had no effect:
.portrait-crop
{
overflow: hidden;
}
img.portrait-crop
{
margin-bottom: -30px;
}
I'm not sure what I'm doing wrong. Any help would be appreciated.
For reference, this is my code.
One possible solution, using only css without affecting your html code is this:
or, adding some div (better solution): http://jsfiddle.net/yoyb9jn7/
I, here a full post How top crop images
You can use CSS3 to handle this very elegantly in a single div without any extra containers :
How about this CSS:
http://jsfiddle.net/91z2wxfy/2/
Your problem is on CSS selectors.
matches an image with portrait-crop class.
but this
Matches an image inside a protrait-crop container.
You can crop
img
s like this:CSS:
Adjust the
height
andwidth
of the container to adjust the dimensions of the croppedimg
and adjust the amount of negativemargin-top
andmargin-left
on theimg
element itself to choose which part of the image to crop to.HTML:
Working Fiddle
EDIT: Alternative solution for a 2 column grid with fixed height rows:
CSS:
HTML:
Working Fiddle