Why does Firefox break my CSS grid with using a horizontal scroll area?

All we need is an easy explanation of the problem, so here it is.

I would like to work with this code:

* {
  margin: 0;
  padding: 0;
}

#container {
  grid-column-gap: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 10px;
}

.text {
  grid-column-start: 1;
  grid-column-end: 3;
  background-color: red;
  /* overflow: hidden; → Firefox needs that. Why? */
}

.horizontal-scroll {
  background-color: green;
  overflow-x: auto;
}

.horizontal-scroll div {
  white-space: nowrap;
  font-size: 30px;
}
<div id="container">
  <div class="text">
    <div>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea
      takimata sanctus est Lorem ipsum dolor sit amet.</div>
    <div class="horizontal-scroll">
      <div>This container is horizontally scrollable. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
        ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</div>
    </div>
  </div>
</div>

Unfortunately, if I use Firefox on macOS, the grid layout gets destroyed. It only works if I add overflow: hidden; to the .text class. But this is not a solution for me, because I need to place an object inside the text area that protrudes from it.

How can this problem be solved?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

NOT WORKING: Remove white-space: nowrap;

* {
  margin: 0;
  padding: 0;
}

#container {
  grid-column-gap: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 10px;
}

.text {
  grid-column-start: 1;
  grid-column-end: 3;
  background-color: red;
  /* overflow: hidden; → Firefox needs that. Why? */
}

.horizontal-scroll {
  background-color: green;
  overflow-x: auto;
}

.horizontal-scroll div {
  /* white-space: nowrap; */
  font-size: 30px;
}
<div id="container">
  <div class="text">
    <div>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea
      takimata sanctus est Lorem ipsum dolor sit amet.</div>
    <div class="horizontal-scroll">
      <div>This container is horizontally scrollable. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
        ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</div>
    </div>
  </div>
</div>

EDIT 1:

Use width: -moz-available; on #text

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply