Table{Table-Layout:Fixed;}TD{White-space:Nowrap;Overflow:Hidden;Text-Overflow:Ellipsis;}
Principle:
This method is used to solveTable CellThe appearance of too much content mainly involves four CSS styles:
1.Table-layout: fixedBecause the default value of table-layout is auto, that is, the width and height of a table depend on the quantity of its content. If the volume of the content cannot be estimated, the final form of the table cannot be guaranteed, fixed.(Note: This style is critical)
2.White-space: nowrapTo ensure that no line breaks are automatically generated regardless of the number of text content in the cell (TD). In this case, the excess content will break through the cell horizontally.
3.Overflow: hiddenHide the part that exceeds the cell.
4.Text-overflow: ellipsisReplace the hidden part with a ellipsis.
:
Source code :
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 strict // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" > < Html Xmlns = "Http://www.w3.org/1999/xhtml" > < Head > < Style Type = "Text/CSS" > Table { Table-Layout : Fixed ; Width : 100% ; } TD { White-space : Nowrap ; Overflow : Hidden ; Text-Overflow : Ellipsis ; Background-color : # Ccc ; } </ Style > </ Head > < Body > < Table > < Thead > < Th > First column </ Th > < Th > Column 2 </ Th > </ Thead > < Tbody > < Tr > < TD > < Span > Ultra-long content, ultra-long Content ultra-long content ultra-long Content </ Span > < Span > Ultra-long content, ultra-long Content ultra-long content ultra-long Content </ Span > </ TD > < TD > Ultra-long content, ultra-long Content ultra-long content ultra-long Content </ TD > </ Tr > </ Tbody > </ Table > </ Body > </ Html >
Compatibility:
Internet Explorer 6, 7, 8, 9 and later
Latest firefox version
Latest chrome version