【问题标题】:How to trim long links with CSS3?如何使用 CSS3 修剪长链接?
【发布时间】:2013-09-10 12:23:10
【问题描述】:

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

【问题讨论】:

    标签: css hyperlink trim ellipsis


    【解决方案1】:

    这里是如何做的答案:

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

    【讨论】:

    • 这里是上面的一个示例:codepen.io/BJack/pen/bBryi 我要加强这个答案的唯一建议是为了 SEO 目的添加与 Title 和/或 Alt 属性相同的链接文本,以便悬停时,用户仍然可以看到完整的标题,并且搜索引擎在链接上有一些额外的上下文。很好的答案@Jagi!
    • 这个。省略号是我们工具箱的一个很棒的补充。
    猜你喜欢
    • 2018-03-11
    • 1970-01-01
    • 1970-01-01
    • 2020-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多