Auto Resize Image in CSS FlexBox Layout and keeping Aspect Ratio?

后端 未结 8 856
长情又很酷
长情又很酷 2020-12-12 12:34

I\'ve used the CSS flex box layout which appears as shown below:

\"enter

If t

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-12 13:23

    HTML:

    CSS:

    .container {
      display: flex;
      flex-direction: row;
      justify-content: center;
      align-items: stretch;
    
      width: 100%;
      height: 100%;
    
      border-radius: 4px;
      background-color: hsl(0, 0%, 96%);
    }
    
    .box {
      border-radius: 4px;
      display: flex;
    }
    
    .box img {
      width: 100%;
      object-fit: contain;
      border-radius: 4px;
    }
    

提交回复
热议问题