How to scale image to fit the container?

后端 未结 7 726
我寻月下人不归
我寻月下人不归 2021-02-02 10:09

I have an image list, I want images scaled into their containers which have same size. like this:

\"a\"

相关标签:
7条回答
  • 2021-02-02 10:52

    In 2017 you can use flex. Additionally you will get the images centered in the thumbnail container: updated fiddle

    .thumbnail {
        height: 300px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        border: solid 1px blue;
    }
    
    .thumbnail img {
        max-width: 100%;
        max-height: 100%;
        display: block;
        margin: 0 auto;
        border: solid 1px red;
    }
    
    0 讨论(0)
提交回复
热议问题