1. Ideas
- CSS control TD content automatically shrinks to three points
- JS Control mouse Hover display all the contents of TD
2. Implement
HTML code:
<!DOCTYPE HTML><HTML><Head> <MetaCharSet= "Utf-8"> <title>TABLE/TD Automatically Hide content</title> <Linkrel= "stylesheet"href= "My.css" /></Head><Body> <TableID= "Idmytable" > <tr> <td> This is a normal display of content </td> <td> This is a content that automatically hides extra-long text content, and the rest will automatically be based on Coltsfoot Hidden, function can execute normally. </td> </tr> </table> <script type= "application/javascript "src= "My.js"></Script></Body></HTML>
CSS code:
Table{width:400px;Border-collapse:collapse;/*set the merge border model for a table*/Table-layout:fixed;/*set the table layout algorithm, only the TD property after setting this value is valid*/}TD{Border:1px solid Blue;Word-break:Keep-all;/*line breaks at the appropriate hyphenation point*/White-space:nowrap;/*text in a specified paragraph does not wrap*/Overflow:Hidden;/*What happens when the content overflows the element box*/Text-overflow:ellipsis;/*What happens when text overflows containing elements, ellipsis meaning ellipsis*/}
JS Code:
Window.onload =function () { varAlltds = document.getElementsByTagName (' TD '); for(vari = 0; i < alltds.length; i++) { varTD =Alltds[i]; Td.onmouseover=function(EV) {if( This. clientwidth < This. ScrollWidth) { This. SetAttribute (' title ', This. textcontent); } }; Td.onmouseleave=function(EV) { This. RemoveAttribute (' title '); }; }};3. Effects
[Timlinux] The TD content of the JavaScript table is more than three dots wide