打破巨大的网址,这样它们就不会溢出

发布于 2024-12-03 04:09:34 字数 395 浏览 1 评论 0原文

有没有办法强制使用巨大的网址,例如http://www.google.de/search?q=65daysofstatic&hl=de&safe=off&prmd=ivnsl&source=lnms&tbm=isch&e i=P9NkToCRMorHsgaunaClCg&sa=X&oi=mode_link&ct=mode&cd=2&ved=0CBkQ_AUoAQ&biw=1697&bih=882在网站中呈现时中断?我宁愿缩短它,但在我工作的地方,他们要求我显示整个网址,但我只有 320px 的空间来显示它,它就溢出了。

Overflow:hidden 也不是一个选项,并且向包含 url 的 td 添加样式将被简单地忽略。

Is there a way to force huge urls such as http://www.google.de/search?q=65daysofstatic&hl=de&safe=off&prmd=ivnsl&source=lnms&tbm=isch&ei=P9NkToCRMorHsgaunaClCg&sa=X&oi=mode_link&ct=mode&cd=2&ved=0CBkQ_AUoAQ&biw=1697&bih=882 break when rendered in the website? I'd rather shorten it but where I'm working they've asked me to show the entire url but I only have a space of 320px to show it and it overflows.

Overflow:hidden, isn't an option either and adding a style to the td where the url is contained is simply ignored.

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

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

发布评论

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

评论(6

蓝海 2024-12-10 04:09:34

在 Chrome 中,自动换行不起作用。您应该使用:

word-break: break-all;

如果您只想将其应用于标签,那么您应该使用:

a {word-break: break-all;}

请注意 break-all 甚至会分割单词,因此一个单词可以在一行上开始并在另一行上结束,这就是为什么最好只将其应用于 a 标记。如果您知道您的链接始终包含单词(例如不是类似 mylink/abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890 ),然后您可以在正文标记级别应用以下内容(这样一个单词就不会分成两行):

body {word-break: break-word;}

In Chrome, word-wrap does not work. You should use:

word-break: break-all;

If you want to apply it only on a tags, then you should use:

a {word-break: break-all;}

Note that break-all will even split words, so a word can start on one line and end on another, that's why it's a good idea to apply it only on a tags. If you know that your links always contain words (e.g. are not something like mylink/abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890 ), then you can apply the following at the body tag level (this way a word is not split onto 2 lines):

body {word-break: break-word;}
香草可樂 2024-12-10 04:09:34

CSS3 有一个新功能:

word-wrap:break-word;

您可以在此处查看一个实例(您必须拥有与其兼容的浏览器)新功能)。

这也与 StackOverflow 采用的技术相同,如果您检查长 URL,您会发现。

或者,您也可以尝试Hyphenator

CSS3 has a new feature:

word-wrap:break-word;

You can see a live example here (you must have a browser compatible with that new feature).

It's also the same tecnique adopted by StackOverflow, if you examine your long URL you will notice.

Alternatively you can try Hyphenator.

站稳脚跟 2024-12-10 04:09:34
-ms-word-break: break-all;
     word-break: break-all;

     // Non standard for webkit
     word-break: break-word;

-webkit-hyphens: auto;
   -moz-hyphens: auto;
        hyphens: auto;

以上适用于 Internet Explorer 8+、Firefox 6+、iOS 4.2、Safari 5.1+ 和 Chrome 13+。

-ms-word-break: break-all;
     word-break: break-all;

     // Non standard for webkit
     word-break: break-word;

-webkit-hyphens: auto;
   -moz-hyphens: auto;
        hyphens: auto;

The above works in Internet Explorer 8+, Firefox 6+, iOS 4.2, Safari 5.1+ and Chrome 13+.

海之角 2024-12-10 04:09:34

溢出包装来救援:

注意:与 word-break 相比,overflow-wrap 只会创建一个
如果整个单词不能单独占一行,则中断
溢出来了。

它具有几乎完整的浏览器支持,当您的长单词(EG URL)无法容纳可用空间时,它将提供帮助

https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-wrap

overflow-wrap to the rescue:

Note: In contrast to word-break, overflow-wrap will only create a
break if an entire word cannot be placed on its own line without
overflowing.

it has pretty much full browser support and will help when your long word (E.G URLs) cannot fit in the available space

https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-wrap

征棹 2024-12-10 04:09:34

我使用此规则仅影响锚点。

.my-paragraph p a[href] {
  word-wrap:break-word;
}

I use this rule to affect only anchors.

.my-paragraph p a[href] {
  word-wrap:break-word;
}
苍暮颜 2024-12-10 04:09:34

尝试下面的 CSS 属性 将长文本 URL 显示为短文本...

white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: inline-block;
max-width: 40%;

try below CSS properties for show long text URL to short...

white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: inline-block;
max-width: 40%;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文