How does a browser detect text-overflow and display ellipsis?

41 Views Asked by At

I implemented a div container

div{ 
    border: 1px solid black;
    width: 75px; 
    padding: 10px; 
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

for <div>Overflowing</div>, Though the text doesn't overflow the div container, but since it enters the padding area, the browser detects an overflow and displays an ellipsis.

I am just curious how it detects the overflow becuase when I printed in the console the related properties, I got the following results.

In Firefox

  • ClientWidth: 95
  • ScrollWidth: 95
  • OffsetWidth: 97

In Chrome

  • ClientWidth: 95
  • ScrollWidth: 102
  • OffsetWidth: 97

For Chrome it makes sense that it's able to identify the overflow since clientwidth < scrollwidth. But how is the firefox browser able to detect the overflow even when scrollwidth is less than equal to the client and offset width ?

0

There are 0 best solutions below