0

I'd like to have a simple flex-wrap, with fixed margin between blocks, and make all that centered.

The last row should be aligned to the left of the previously centered blocks if it's not complete.

Here is what I've tried:

<div class="flow">
    <div class="flow2">
        <div class="block"></div>
        <div class="block"></div>
        <div class="block"></div>
        <div class="block"></div>
        <div class="block"></div>
    </div>
</div>

CSS :

.flow {
    display: flex;
    justify-content: center; /* Does nothing */
}

.flow2 {
    display: flex;
    flex-wrap: wrap;
}

.block {
    width: 300px;
    height: 66px;
    margin-right: 15px;
    margin-left: 15px;
    background-color: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(0, 0, 0, 0.4);
    border-radius: 5px;
    margin-bottom: 10px;
}

Here is a fiddle to try that: http://jsfiddle.net/oe76j64L/2/

I'd like everything to be like that inside flow2, except centered inside flow. This should stay consistent when I resize the view.

How can I achieve that using CSS ?

Here is a roughly drawn picture for more explanation: https://i.stack.imgur.com/rhp1e.png

Up, what i have, Down, what I want.

blue112
  • 52,634
  • 3
  • 45
  • 54

0 Answers0