Responsive CSS Grid with persistent aspect ratio

后端 未结 3 1475
长发绾君心
长发绾君心 2021-02-07 18:26

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:46

    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;
    }

提交回复
热议问题