1

I have the following code:

.clJustify {
  width: 400px;
  height: 25px;
  margin-left: auto;
  margin-right: auto;
  border: 1px solid red;
  text-align: justify;
}
.clJustify:after {
  content: "";
  display: inline-block;
  width: 100%;
}
<!doctype html>
<html>

<head>
  <meta charset="utf-8">
  <title>Justify Test</title>
</head>

<body>
  <p class="clJustify">This is text that should be jus-</p>
  <p class="clJustify">tified and also hyphenated.</p>
</body>

</html>

Please don’t ask me why I want to do this. :-)

My problem is: In FF and Chrome this results in two lines of text that fill the space of the <p>. But IE breaks the first line before the “jus-” and puts it into a separate line. A line without a hyphen will be displayed as expected, it is the hyphen at the end that confuses IE, it seems.

Here is a screenshot from Internet Explorer:

Screenshot from IE

And here is a screenshot from Firefox:

Screenshot from FF

Any ideas how I could prevent IE from breaking the line? The suggested answers to older posts don't address the problem of the hyphen.

bad_coder
  • 11,289
  • 20
  • 44
  • 72

1 Answers1

1

Try text-align-last and -ms-text-align-last, this works in IE:

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Justify Test</title>
    <style type="text/css">
      .clJustify{
        width: 400px;
        height: 1.5em;
        margin-left: auto;
        margin-right: auto;
        border: 1px solid red;
        text-align: justify;
        -ms-text-align-last: justify;
        text-align-last: justify;
      }
      .clJustify:after{
        content: " ";
        display: inline-block;
        width: 100%;
      }
    </style>
  </head>

  <body>
    <p class="clJustify">This is text that should be jus-<br>&nbsp;</p>
    <p class="clJustify">tified and also hyphenated.</p>
  </body>
</html>
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252