6

I have a grid container with a fixed width and a single row and column containing a single word. When I use the fr unit to size the column, overflow-wrap: break-word does not wrap the word causing the word in the column to overflow.

To the best of my understanding and docs, overflow-wrap: break-word is supposed to break at any point to prevent overflow if there is no acceptable break point.

Two things seem to fix this. One is to have a px unit for column size. Second is having overflow: hidden on the text container. I observed the same behaviour on Chrome(v73) and Firefox(v66).

Does anybody know the reason behind this behaviour ?

https://jsfiddle.net/vdx90qeg/2/

<div class="container">
  <div class="item1">
    someverylongword
  </div>
</div>
.container {
  display: grid;
  grid-template-columns: 1fr;
  /*using 'px' instead of 'fr' works */
  grid-template-areas: "item1";
  width: 80px;
  border: 1px solid black;
}

.item1 {
  grid-area: "item1";
  overflow-wrap: break-word;
  /* overflow: hidden; */
  /* works when uncommented */
}
Yunus Can Emre
  • 174
  • 2
  • 7
  • 1
    adding `min-width: 0` or `overflow` property other than *visible* solves this (the default `min-width` or `min-height` for a *grid item* is *auto*)... see https://stackoverflow.com/questions/55773596 – kukkuz May 05 '19 at 05:55
  • yes that does also fix it, as does setting `minmax(0, 1fr)` to the column. But I still don't understand why `overflow-wrap` doesnt get taken into account. – Yunus Can Emre May 06 '19 at 06:24

1 Answers1

9

Looks like this problem is very similar to what https://css-tricks.com/preventing-a-grid-blowout/ solves

Set column to minmax(0, 1fr) instead of just 1fr. This approach gives the column a minimum width which was default to auto. The goal is to turn the column from indefinitely sized container to a definitely sized container.

codepen link: https://codepen.io/thissushiguy/pen/mYdxjb

Yuxi
  • 106
  • 3