Home > Software design >  Why does Firefox break my CSS grid with using a horizontal scroll area?
Why does Firefox break my CSS grid with using a horizontal scroll area?

Time:04-03

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 >
    <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 >
      <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?

CodePudding user response:

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

  • Related