防止 ? (问号)避免被视为空格之类的分隔符

发布于 2024-09-15 16:21:20 字数 547 浏览 3 评论 0原文

有什么办法可以防止“?”避免在 HTML/CSS 中被视为类似空白?这是默认行为,还是我做错了什么?

我有一个 div 包含一个很长的 URL(长度是动态的)。我希望 URL 将问号视为任何其他字符,而不是强制在该字符处换行,但我不想使用 white-space:nowrap;,因为这会导致整行溢出 div,这不是所需的行为。

所需的行为是文本在 div 末尾换行到下一行,就像没有问号时一样。 alt text

这可能并不重要,但以下是它们的 CSS 属性:

 a{color:green; font-weight: bold;} .ycpreviewbox{ margin: 0 auto; padding: 2em; background-color: #C7E2ED;} .

以下是它在较短 URL 下的行为方式: 替代文字

Is there any way to prevent '?' from being treated as white-space-like in HTML/CSS? Is this default behavior, or am I doing something wrong?

I have a div that holds a very long URL (the length is dynamic). I want the URL to treat the question mark as any other character and not force a line break at that character, but I don't want to use white-space:nowrap;, since that will cause the entire line to overflow out of the div, which is not a desired behavior.

The desired behavior is for the text to wrap at the end of the div onto the next line, as it would if it weren't for the question mark.
alt text

It likely doesn't matter, but here are their CSS properties:

 a{color:green; font-weight: bold;} .ycpreviewbox{ margin: 0 auto; padding: 2em; background-color: #C7E2ED;} .

Here is how it behaves with a shorter URL:
alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

云醉月微眠 2024-09-22 16:21:20

我遇到了同样的问题,这是我使用的两行CSS:

{
    word-wrap: break-word;
    white-space: pre;
}

I had the same issue, here are the two lines of css I used:

{
    word-wrap: break-word;
    white-space: pre;
}
一场春暖 2024-09-22 16:21:20

在 HTML5 中,您还可以使用 表示 建议换行符...
也许这会有所帮助,告诉浏览器应该在哪里断行,而不是让它自己决定......

In HTML5 you can also use <wbr> for suggesting line breaks...
maybe this could help, by telling the browser where it should break the line, instead of letting it decide by itself...

迷途知返 2024-09-22 16:21:20

尝试使用 nobr 标签。

Try the nobr tag.

薄情伤 2024-09-22 16:21:20

您可能会考虑在多个字符后插入空格或换行符,而不是依赖浏览器来决定在何处中断字符串。

You might consider inserting a space or linebreak after a number of characters instead of relying on the browser to decide where to break your string.

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