2

In this code, hyphens don't seem to work properly:

.container {
  width: 100px;
  background: olive;
  overflow-wrap: break-word;
  hyphens: auto;
  margin-bottom: 10px;
  padding: 0px 15px;
  box-sizing: border-box;
}
<html lang="en">

<div class="container">
  Rozplombovani dlazdice
</div>

<div class="container">
  fadsafweafewfsdafdsafsdfadsffaweae
</div>

</html>

The first .container breaks word, but hyphen is missing.

In the second .container, the text breaks line in four places, and four of them get a hyphen, but one of them doesn't

enter image description here

Here is a demo

What is going on there?

Michal Kurz
  • 1,592
  • 13
  • 41
  • While I've updated your question, by converting the code you supplied into a runnable "Stack Snippet" that code doesn't reproduce the problem you describe, in that the second block of text has no hyphens anywhere. I'm using Firefox 102 on Ubuntu, though. So maybe it's a browser-specific issue. – David Thomas Jul 14 '22 at 16:08
  • @DavidThomas This is because `` tags needs `lang` attribute to be set in order for hyphenation to work - for example: ``. The snippet you generated does not have this. Once I add that attribute to result inside dev tools, hyphens appear. I also added two styles, so now the code snippet gives a result indentical to the picture, once we add `lang` attribute – Michal Kurz Jul 14 '22 at 16:28
  • @DavidThomas I added the html tag explicitely to the example, and now it mimics the behaviour in picture – Michal Kurz Jul 14 '22 at 16:32
  • I have to admit that I had no idea about that requirement; thank you for (for both letting me know, and for updating the snippet). – David Thomas Jul 14 '22 at 16:34
  • Should the lang attribute be 'cs' in this case? – A Haworth Jul 14 '22 at 16:43
  • @AHaworth I wasn't aware that this could make any difference... but changing the lang to "cs" makes all hyphens disapear, which is interesting... do you happen to know why? – Michal Kurz Jul 14 '22 at 17:05
  • No idea I'm afraid - are there very different rules for hyphenating Czech? – A Haworth Jul 14 '22 at 17:10

0 Answers0