I have an issue with the space-evenly
value for justify-content
on Chrome mobile (it works fine on Desktop and on Firefox mobile).
I managed to produce a minimal example: Example
I have a flex container in a row direction and I want the elements to be spaced evenly, as intended when using space-evenly
. It works on desktop, but on Chrome mobile (version 59 on Android), however, the elements are aligned on the left. Here is a comparison of the two: Comparison
center
and space-around
values work as intended, however, but I really want to use space-evenly
or an equivalent (the flex-wrap: wrap
behavior is also important to me).
Here is my HTML:
<div class="container">
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
</div>
And here is my CSS:
.container {
display: flex;
flex-direction: row;
justify-content: space-evenly;
flex-wrap: wrap;
background: lightgrey;
}
.element {
margin: 8px;
width: 42px;
height: 42px;
background: black;
}
Thanks in advance!
I have an issue with the space-evenly value for justify-content on Chrome mobile (it works fine on Desktop and on Firefox mobile). I have a flex container in a row direction and I want the elements to be spaced evenly, as intended when using space-evenly.
justify-content The CSS justify-content property defines how the browser distributes space between and around content items along the main-axis of a flex container, and the inline axis of a grid container. The interactive example below demonstrates some of the values using Grid Layout.
The "space-evenly" value for the justify-content property distributes the space between items evenly. It is similar to space-around but provides equal instead of half-sized space on the edges.
It works on desktop, but on Chrome mobile (version 59 on Android), however, the elements are aligned on the left. Here is a comparison of the two: Comparison center and space-around values work as intended, however, but I really want to use space-evenly or an equivalent (the flex-wrap: wrap behavior is also important to me).
There is no solution yet for multi-line/wrapped space-evenly
for browsers that doesn't support it.
When using flex-wrap: wrap
you will need to i.e. set a fixed padding on the flex container, margin on the items or use a script.
If it is possible to wrap each row you can use the pseudo elements in combination with space-between
to achieve the exact same result as space-evenly
give.
In below sample the space-between
will take the zero width pseudo elements into account when calculating the space between, hence producing the same result.
.container {
display: flex;
flex-direction: row;
justify-content: space-between;
/* flex-wrap: wrap; */
/* align-items: flex-start; if "img", this will prevent it from stretching */
background: lightgrey;
}
.element {
margin: 8px;
width: 42px;
height: 42px;
background: black;
}
.container::before,
.container::after {
content: '';
}
<div class="container">
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With