I use the pseudo element :after
to align the last row of the block list on the left. I use space-evenly
to justify the blocks. My problem is that the block on the last line is not aligned with the user because :after
takes up space. How can I solve this problem?
.exposegrid { width: 500px; display: flex; flex-flow: row wrap; justify-content: space-evenly; &:after { content: ""; flex: auto; } } .exposetab { width: 100px; height: 66px; background-color: rgba(255, 255, 255, 0.2); border: 1px solid rgba(0, 0, 0, 0.4); border-radius: 5px; box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2); margin-bottom: 10px; }
<div class="exposegrid"> <div class="exposetab"></div> <div class="exposetab"></div> <div class="exposetab"></div> <div class="exposetab"></div> <div class="exposetab"></div> <div class="exposetab"></div> <div class="exposetab"></div> <div class="exposetab"></div> <div class="exposetab"></div> <div class="exposetab"></div> <div class="exposetab"></div> <div class="exposetab"></div> <div class="exposetab"></div> <div class="exposetab"></div> </div>
The
:after pseudo-element takes up space in the Flex container and interferes with the alignment of the items in the last row, which is the root cause of your problem. Using margins on the :after pseudo-element as an alternative to flex auto is one way to solve this problem. This is the latest version of CSS: