防止内联块在空白处换行:pre?
看来 Chrome 正在包装一个 inline-block 元素,如果它位于行尾,即使它周围有一个空白:pre 容器,并且带有溢出:auto。是否有可行的解决方案可以在不更改内容的情况下防止这种情况发生?
<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>
至少必须使用换行符来保留空白。空格和制表符可能会被压缩。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个错误已经4年了,并且仍然存在于最新的 Chrome 和 Safari 中,但我确实找到了解决方法不会添加不需要的空格,即添加一个空的
:after
伪元素: http:// /jsbin.com/oQuBAmIJ/1/editThis 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尝试将空白设置更改为
white-space: nowrap
。Try changing your white-space setting to
white-space: nowrap
instead.