html - 自动换行问题

发布于 2024-09-04 00:53:54 字数 314 浏览 6 评论 0原文

我在 div 中有一些文本,我希望它能够换行以适合文档宽度(没有任何滚动!)。我不想有断字,例如 div {word-wrap: break-word;}

例如(这就是我想要得到的):

hello world! today is a 
good day.

但不是:

hello world! today is a  good day.

或:

hello world! today is a go
od day.

I have some text in div, and I want it to wrap to fit document width (without any scrolls!). I don't want to have word-break, like div {word-wrap: break-word;}

For example (this is what I want to get):

hello world! today is a 
good day.

But not:

hello world! today is a  good day.

or:

hello world! today is a go
od day.

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

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

发布评论

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

评论(2

一抹微笑 2024-09-11 00:53:54

我不确定你想要什么,只是这个吗?

<div style="width:200px">hello world! today is a good day.</div>

I'm not sure what you want, is it just this?

<div style="width:200px">hello world! today is a good day.</div>
浪菊怪哟 2024-09-11 00:53:54

也许 标签可以帮助您。
该标签允许浏览器在其所在位置插入换行符,
“如果浏览器想要的话”。

This 这是一个记录 IEbreak 行为的页面,您可以将其视为一个模型来进行一些调试。

如果您想启动 jQuery 在 html 中脚本注入 在这里您可以看到 John Resig 的示例

您可以在此处阅读有关它的完整参考

这里讨论了类似的主题

Maybe the <wbr> tag could help you.
This tag allow the browser to insert a line break where it's positioned,
"if the browser want" .

This is a page were the IEbreak behavior is documented, you can take It as a model to do some debugging.

And if you want to fire-up jQuery to script-inject <wbr> in your html here you can se an example from John Resig.

You can read a complete reference about It here

A similar topic was discussed on SO here.

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