On Firefox, how can you justify text that has the white-space: pre-wrap;
CSS attribute?
I need the pre-wrap
to prevent the browser from collapsing whitespaces, but it breaks the text-align: justify;
property. See http://jsfiddle.net/xpp48knq/ for example.
I would be ok with any solution that doesn't collapse spaces and that justifies content.
Here's some workaround for ur problem.
U should remove 'white-space: pre-wrap' from the element, and replace all spaces in text to ' '(mean zero-width space plus space). And everything will be working fine in every major browser.
Here's some example: https://jsfiddle.net/gvm3x354/
<div id='output' class='text'>
</div>
.text {
border: 1px solid black;
text-align: justify;
width: 200px;
height: auto;
}
var output = document.getElementById('output'),
text = 'I\'m a justified text with multiple spaces between words. Really cool, so js. Found better workaround? E-mail me!';
text = text.replace(/\s/g, '​ ');
output.innerHTML = text;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With