2

i am trying to wrap a long text inside a table but facing the problem that the long text overlaps other content.

Example:

table td {
  white-space: nowrap;
  max-width: 10em;
  overflow: hidden;
  text-overflow:ellipsis;
}

table td:hover {
    overflow: visible;
}
<table>
    <thead>
        <tr>
            <th>Headline 1</th>
            <th>Headline 2</th>
            <th>Headline 3</th>
        </tr>  
    </thead>
    <tbody>
        <tr>
            <td>Bet at home</td>
            <td>10</td>
            <td>80%</td>
        </tr> 
        <tr>
            <td>MOSER 2384 Schermaschine Moser</td>
            <td>20</td>
            <td>40%</td>
        </tr> 
        <tr>
            <td>Bg24 Single 600x120</td>
            <td>30</td>
            <td>50%</td>
        </tr> 
    </tbody>    
</table    

Is there a way to avoid this maybe by adding a non transparent background to the content? How can i handle this problem?

Regards, Kai

3
  • @Nit hover the second item. Commented Mar 29, 2015 at 17:58
  • Why not just get rid of the line where you TELL it not to wrap?: white-space: nowrap; Commented Mar 29, 2015 at 17:59
  • Jumpy but have you tried to add white-space normal or pre-wrap; Commented Mar 29, 2015 at 18:00

5 Answers 5

1

Just add whitespace:normal in your hover.

table td {
  white-space: nowrap;
  max-width: 10em;
  overflow: hidden;
  text-overflow:ellipsis;
}

table td:hover {
    overflow: visible;
    white-space: normal;
}
<table>
    <thead>
        <tr>
            <th>Headline 1</th>
            <th>Headline 2</th>
            <th>Headline 3</th>
        </tr>  
    </thead>
    <tbody>
        <tr>
            <td>Bet at home</td>
            <td>10</td>
            <td>80%</td>
        </tr> 
        <tr>
            <td>MOSER 2384 Schermaschine Moser</td>
            <td>20</td>
            <td>40%</td>
        </tr> 
        <tr>
            <td>Bg24 Single 600x120</td>
            <td>30</td>
            <td>50%</td>
        </tr> 
    </tbody>    
</table    

Sign up to request clarification or add additional context in comments.

3 Comments

Could be a solution but it would be nice to avoid a new line on hover.
It would be nice if there is no new line when hovering and the long text also should not overlap the other content. So when the long text is shown on hover it should be readable.
no new line and do not overlap the other columns. It means your column size should change that would not be very good. Instead use a tool tip. Design the tool tip so that it differs from the one you are already using.
0

I wouldn't do anything on hover (i.e. remove table td:hover). Because when you set overflow to hidden, by default a tooltip is already displayed when you hover, which shows you the full text - it is significally easier to read than if you expand and move the table rows by expanding some of them.

table td {
  white-space: nowrap;
  max-width: 10em;
  overflow: hidden;
  text-overflow:ellipsis;
}
<table>
    <thead>
        <tr>
            <th>Headline 1</th>
            <th>Headline 2</th>
            <th>Headline 3</th>
        </tr>  
    </thead>
    <tbody>
        <tr>
            <td>Bet at home</td>
            <td>10</td>
            <td>80%</td>
        </tr> 
        <tr>
            <td>MOSER 2384 Schermaschine Moser</td>
            <td>20</td>
            <td>40%</td>
        </tr> 
        <tr>
            <td>Bg24 Single 600x120</td>
            <td>30</td>
            <td>50%</td>
        </tr> 
    </tbody>    
</table    

1 Comment

The tooltip/title-attribute is already used by other informations, so cant be used for the long text.
0

What about using word-break attibute to element?

table td{      
    word-break: break-all;
}

Comments

0

I-m not sure if that is what are you looking for , but I couldn't find another solution

table td:hover {
    overflow: visible;
    max-width:100%;
}

fiddle here

Comments

0

Try adding

whitespace: normal; 

or try

white-space: pre-wrap; 

in your hover.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.