Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

space-evenly (justify-content) not working on Chrome mobile

Tags:

html

css

flexbox

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!

like image 893
Maverick Chardet Avatar asked Aug 10 '17 11:08

Maverick Chardet


People also ask

Does justify-content work with space-evenly on Chrome mobile?

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.

What does justify content do in CSS?

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.

What does space-evenly mean in justify-content?

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.

Does space-evenly work on Chrome mobile?

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).


1 Answers

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>
like image 139
Asons Avatar answered Oct 20 '22 04:10

Asons