I used flexbox for layouts, and CSS floats as a reserve for older browsers. In general, this works well, as browsers that understand display: flexwill ignore the float for any flex items.
However, one place I ran into a problem with this approach is clearfix. Clearfix is a widely used hack that uses an invisible :afterpseudo-element to make the container properly clean / contain any elements inside it floated. However, the problem is that this pseudo-element is considered as an element of flexibility by browsers that support flexbox, which can lead to unexpected layout problems. For example, if you have two flex elements and use justify-content: space-between, instead of being located at the beginning and end of the flex container, they will be displayed at the beginning and middle, with an invisible clearfix ::afterpseudo-element, the end position.
My question is: is there a way to use clearfix along with the flexbox layout without causing these problems?
source
share