Responsive CSS Grid with persistent aspect ratio

后端 未结 3 1285
我寻月下人不归
我寻月下人不归 2021-02-07 18:24

My goal is to create a responsive grid with an unknown amount of items, that keep their aspect ratio at 16 : 9. Right now it looks like this:

3条回答
  •  一生所求
    2021-02-07 18:43

    Maybe I am not able to understand the question, but how do you plan to keep item aspect ratio 16:9, while wanting to scale items with screen width?

    If you are fine with items having enlarged width in between screen sizes, this can work:

    .grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
        grid-template-rows: 1fr;
        grid-gap: 20px;
     }
    .item {
        height: 90px;
        background: grey;
    }

提交回复
热议问题