Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent inline-block from wrapping on white-space: pre?

Tags:

css

word-wrap

It seems Chrome is wrapping an inline-block element if it is at the end of a line even if there is a white-space:pre container around it with overflow: auto. Is there a workable solution to prevent this from happening without changing the content?

<div style="width:400px;height:200px;overflow:auto;white-space:pre">
The span should be at the end of this text, however, it wraps to the next line.<span style="width:1px;display:inline-block;height:1em;background:red"></span>
</div>

The white-space must be preserved using newlines at least. Spaces and tabs may be compressed.

like image 617
bmeck Avatar asked Feb 23 '10 04:02

bmeck


2 Answers

This bug is 4 years old and still present in the latest Chrome and Safari, but I did find a workaround that doesn't add undesirable whitespace, which is to add an empty :after pseudo-element: http://jsbin.com/oQuBAmIJ/1/edit

like image 141
Han Seoul-Oh Avatar answered Nov 14 '22 18:11

Han Seoul-Oh


Try changing your white-space setting to white-space: nowrap instead.

like image 20
Steve Danner Avatar answered Nov 14 '22 19:11

Steve Danner