Can I change the “justify-content” value depending on the number of elements in the flex container?

后端 未结 4 1792
渐次进展
渐次进展 2020-12-21 02:35

I am working on an image gallery on a legacy site. I can\'t use anything other than regular old HTML/jQuery or JS/CSS. I know this would be a lot easier with Bootstrap or so

4条回答
  •  青春惊慌失措
    2020-12-21 03:32

    Depending on what you need to support, it might make more sense to use CSS grid layouts (as TylerH pointed out, CSS Grids do not have universal browser support). Check the documentation for further info: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout

    .flex-container {
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      grid-gap: 10px;
      grid-auto-rows: minmax(100px, auto);
    }
    example image

    Image 1

    example image

    Image 2

    example image

    Image 3

    example image

    Image 4

    example image

    Image 5

    example image

    Image 6

    example image

    Image 7

提交回复
热议问题