防止内联块在空白处换行:pre?

发布于 2024-08-23 03:13:47 字数 430 浏览 2 评论 0原文

看来 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深居我梦 2024-08-30 03:13:47

这个错误已经4年了,并且仍然存在于最新的 Chrome 和 Safari 中,但我确实找到了解决方法不会添加不需要的空格,即添加一个空的 :after 伪元素: http:// /jsbin.com/oQuBAmIJ/1/edit

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

苏别ゝ 2024-08-30 03:13:47

尝试将空白设置更改为 white-space: nowrap

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文