防止 ? (问号)避免被视为空格之类的分隔符
有什么办法可以防止“?”避免在 HTML/CSS 中被视为类似空白?这是默认行为,还是我做错了什么?
我有一个 div 包含一个很长的 URL(长度是动态的)。我希望 URL 将问号视为任何其他字符,而不是强制在该字符处换行,但我不想使用 white-space:nowrap;
,因为这会导致整行溢出 div,这不是所需的行为。
所需的行为是文本在 div 末尾换行到下一行,就像没有问号时一样。
这可能并不重要,但以下是它们的 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.
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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我遇到了同样的问题,这是我使用的两行CSS:
I had the same issue, here are the two lines of css I used:
在 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...
尝试使用 nobr 标签。
Try the nobr tag.
您可能会考虑在多个字符后插入空格或换行符,而不是依赖浏览器来决定在何处中断字符串。
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.