Crop image in CSS

后端 未结 8 515
情书的邮戳
情书的邮戳 2021-01-12 07:23

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 t

相关标签:
8条回答
  • 2021-01-12 08:15

    How about this CSS:

    img { height: 280px; }
    .portrait-crop { height: 560px; }
    

    http://jsfiddle.net/91z2wxfy/2/

    0 讨论(0)
  • 2021-01-12 08:22

    One possible solution, using only css without affecting your html code is this:

    /* Fix for portrait */
    .portrait-crop {
         width:50%;
         overflow:hidden;
         height:179px;
         display:inline-block;
     }
     .portrait-crop img {
           width:100%;
           height:auto;
     }
    

    or, adding some div (better solution): http://jsfiddle.net/yoyb9jn7/

    0 讨论(0)
提交回复
热议问题