Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Cell Value if There is Overflow

Tags:

html

css

I am fairly sure this is impossible with just html/css, but I wanted to ask just in case. Let's say I have <div> inside a <td>, the div has the overflow: hidden; style. Instead of the overflow just being cut off, I want to:

  1. Detect that there is overflow.
  2. React by deleting the last 3 letters of div content and add a "..." at the end.

Edit: I missed a critical detail when originally asking the question - is this possible to do with overflow-y, so I can still have multiple lines of text before it generates the "..."?

PLNKR for testing

like image 412
VSO Avatar asked Nov 03 '15 20:11

VSO


People also ask

How do you change the overflow in Excel?

Select the cells you want to prevent from overflowing. On the Home tab, in the Alignment group, click the Dialog launcher (a small arrow in the lower-right corner of a group). On the Alignment tab of the Format Cells dialog box, choose Fill in the Horizontal drop-down list.

Is there any way to allow cell text overflowing into next cell even though next cell contains a formula resulting on an empty cell?

All you can do is, right click that cell, choose Format cell, then in the text section, set text to wrap and set the cell height to automatic . . . Power to the Developer!

How do I change cell value depending on another cell value?

Display default value based on another cell with VLOOKUP In Excel, you can use the VLOOKUP function to quickly show value based on the corresponding value. D1 is the value you look up based on, A1:B7 is the data range you look for, 2 indicates to find the value in second column of the looking for range.


1 Answers

Example taken from the link I provided in the OP comments:

.element-to-cut-off {
  width: 250px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

From your plnkr, change div class to this:

div{
    background-color:cyan;
    width: 80px;
    height: 40px; 
    overflow: hidden; 
    white-space: nowrap;
    text-overflow: ellipsis;
}

Change your plnkr to this for multi line:

div{
  background-color:cyan;
  width: 80px;
  height: 40px; 
  overflow: hidden; 
  -webkit-line-clamp: 2; // number of lines before ellipsis kicks in
  -webkit-box-orient: vertical;
  display: -webkit-box;
  overflow: hidden;
  text-overflow: ellipsis;
}

I will stress I don't know which browsers can use this css3 and don't have time to test all, but works fine in Chrome 46

like image 169
StudioTime Avatar answered Sep 21 '22 01:09

StudioTime