当处理修剪长链接时,我们必须做额外的工作服务器端,如检查字符串长度和添加省略号,如果它很长但我们可以使用CSS3轻松完成。
答案 0 :(得分:2)
以下是如何做到的答案:
/* Only links with "href" attribute */
a[href] {
/* Add ellipsis at the end if text does not fit in given width */
text-overflow: ellipsis;
/* Have to add this line to make upper line work */
overflow: hidden;
/* Decide what is the longest link width in given units (px, em, rem etc.) */
max-width: 300px;
/* Element has to be inline-block to have width and fit inline in the same time */
display: inline-block;
/* We want to have all the link in one line without wrapping */
white-space: nowrap;
}