How to center align a grid of divs in a flex container?

后端 未结 2 440
情话喂你
情话喂你 2021-01-22 18:44

I am trying to centre align the 3 column grid (which is made up of 6 flex- items) placed in a flex-container div. (Refer to image attached

相关标签:
2条回答
  • 2021-01-22 19:41

    You can use justify-content on the flex container to align items over its main axis. Take a look at this example: https://jsfiddle.net/eL650y3e/

    Sources:

    • https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content
    • https://css-tricks.com/snippets/css/a-guide-to-flexbox/
    0 讨论(0)
  • 2021-01-22 19:43

    I would try setting margin:auto; `

    .flex-item {
        width: 23%;
        height: 360px;
        margin: 10px;
        order: 1;
        border-radius: 3px;
        padding: 0 10px 40px 10px;
        margin:auto;
    }`
    
    0 讨论(0)
提交回复
热议问题