make overflowing text readable with css

lordvlad

i have a table with fixed-width content. which does not always fit. i would like to truncate the text to a fixed width and append an ellipsis. the full text should be visible when hovering the text. this works fine, except that the now visible text covers text to its right. how can i prevent this?

this is what i've got so far.

.truncate {
  max-width: 5em;
  overflow: hidden;
  display: inline-block;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.truncate:hover {
  overflow: visible
}

jsFiddle

Viktor S.

Here is how your approach could be improved so text will be readable when hovered.

Updated HTML:

<table>
    <tr>
        <td><span><a class="truncate">faksjfaklsjf asjf lajslfk jasklfj alkjsfkl jalskfjla</a></span>
        </td>
        <td>
            <span>
            <a class="truncate">
                faskfjalskfj alkfj laksj flkajfl kajfl ajfkl ajsl
            </a>
            </span>
        </td>
    </tr>
</table>

See how <a> is now wrapped with <span>.

And here is updated CSS:

td {
    width: 5em;
} 
span {
    height:1.2em;
    position:relative;
    display: inline-block;
}
.truncate {
     max-width: 5em;
     overflow: hidden;
     display: inline-block;
     text-overflow: ellipsis;
     white-space: nowrap;

 }
 .truncate:hover {
    position:absolute;
    max-width: none;
    background:#fff;     
    z-index:100;
    overflow:visible;    
 }

span is relatively positioned, so absolute item inside it will be shown in a new layer and will take virtually no space (will not shift other text when overflow:hidden removed).

a.truncate will now became absolutely positioned on hover and will loose max width restriction. background:#fff is required to

Demo

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

CSS Make text over image more readable

From Dev

CSS Make text over image more readable

From Dev

Why is this text overflowing and how to not make it overflow?

From Dev

CSS Prevent text from overflowing the parent div

From Dev

How can I make text in meld readable?

From Dev

How can I make text in meld readable?

From Dev

Text overflowing from div

From Dev

Swift, hide overflowing text

From Dev

Text overflowing beyond the div

From Dev

Handle Overflowing Text in TextView

From Dev

Text overflowing in site wordpress

From Dev

CSS Gutter overflowing body

From Dev

CSS - How can I make a font readable over any color?

From Dev

CSS - How can I make a font readable over any color?

From Dev

CSS format doesn't make article readable on mobile

From Dev

Bootstrap modal horizontal text overflowing

From Dev

Align text to the right, overflowing to the left

From Dev

Overflowing text in hidden speech bubbles

From Dev

Margin for overflowing text in new line

From Dev

Make a file more readable

From Dev

RRULE to human readable text

From Dev

How to make flashing text in Css?

From Dev

How to make flashing text in Css?

From Dev

how apple's music app defines which color to use for text to make them readable?

From Dev

How to make a SVG diagram not truncate overflowing shapes?

From Dev

What CSS can I use to allow the text to be readable no matter what is behind it?

From Dev

Button specified in vm's has overflowing text

From Dev

Text horizontally overflowing into next inline div

From Dev

Struggling with text overflowing from within a flexbox