Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Underline an HTML ellipsis

Tags:

html

css

ellipsis

I am using text-overflow: ellipsis to clip text that is inside of a span that is inside of an anchor. The ellipsis character is not underlined when I hover which causes a small gap. Is there a way to fix this?

like image 796
theblang Avatar asked Oct 15 '12 20:10

theblang


2 Answers

Yes, you can do this - set text-decoration: none and instead of that use border-bottom - DEMO

a {
    display: block;
    width: 185px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none;

    border-bottom: 1px solid transparent;
}

a:hover {
    border-bottom: 1px solid #000;
}
like image 188
Zoltan Toth Avatar answered Oct 19 '22 17:10

Zoltan Toth


If some one find this, like me, and do not like the fact that the border-bottom line is too far away this code might help DEMO

a {
    display: block;
    width: 185px;
    background: beige;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none;
    color: #000;
    position: relative;
}

a:hover::before {
    content: '';
    position: absolute;
    bottom: 2px;
    right: 0;
    left: 0;
    border-bottom: 1px solid black;
}

Still a hack, but you know... :)

like image 34
Simon Ström Avatar answered Oct 19 '22 18:10

Simon Ström