Home  >  Article  >  Web Front-end  >  html + CSS实现文字超出长度隐藏,显示省略号_html/css_WEB-ITnose

html + CSS实现文字超出长度隐藏,显示省略号_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:51:181201browse

表格:

table{
  table-layout: fixed;
}
}
t
td{
 
   white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
}

本方法用于解决表格单元格内容过多时的美观问题,主要涉及到4句CSS样式:
1. table-layout: fixed 由于table-layout的默认值是auto,即table的宽高将取决于其内容的多寡,如果内容的体积无法估测,那么最终表格的呈现形式也无法保证了,fixed一下就好了。(注意:此样式是关键)
2. white-space: nowrap 是为了保证无论单元格(TD)中文本内容有多少,都不会自动换行,此时多余的内容会在水平方向撑破单元格。
3. overflow: hidden 隐藏超出单元格的部分。
4. text-overflow: ellipsis 将被隐藏的那部分用省略号代替。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn