css - 如何使用 CSS3 修剪长链接?

标签 css hyperlink trim ellipsis

在处理修剪长链接时,我们必须在服务器端做额外的工作,例如检查字符串长度,如果太长则添加省略号,但我们可以使用 CSS3 轻松完成。

最佳答案

这里是如何做到这一点的答案:

/* 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;
}

关于css - 如何使用 CSS3 修剪长链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18718881/

相关文章:

javascript - 链接元素加载

javascript - jquery 从格式 01/02/2010 的日期开始 trim 前导零

html - iPhone 上 Unicode 复选标记 2714 的颜色没有改变

c++ - 链表类

javascript - 悬停时显示随机图像

hyperlink - 在 GitLab 页面上发布 Docusaurus 网站时如何解决内部链接问题

matlab - 如何从 n 维数组中修剪前导和尾随 NaN 值?

wordpress - 我想在使用 wp_trim_words 时允许 html 标签

html - CSS Floated Div 高度问题,没有简单的解决办法?

html - 用颜色填充表格单元格