zoukankan      html  css  js  c++  java
  • table表格中文字超出显示省略号

    原理:

    本方法用于解决表格单元格内容过多时的美观问题,主要涉及到5句CSS样式:

    1. table-layout: fixed 由于table-layout的默认值是auto,即table的宽高将取决于其内容的多寡,如果内容的体积无法估测,那么最终表格的呈现形式也无法保证了,fixed一下就好了。(注意:此样式是关键
    2. white-space: nowrap 是为了保证无论单元格(TD)中文本内容有多少,都不会自动换行,此时多余的内容会在水平方向撑破单元格。
    3. overflow: hidden 隐藏超出单元格的部分。
    4. text-overflow: ellipsis 将被隐藏的那部分用省略号代替。
    5. 可设置 td 宽度属性为:width max-width
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style>
            table tbody td {
                text-overflow: ellipsis;
                white-space: nowrap;
                overflow: hidden;
            }
        </style>
    </head>
    <body>
     <table width="50%" border="1" style="table-layout:fixed;"> 
        <thead> 
            <th> 第一列 </th> 
            <th> 第二列 </th> 
        </thead> 
        <tbody> 
            <tr> 
                <td> 
                    <span>超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容 超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容</span>
                    <span>超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容 超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容</span> 
                </td> 
                <td> 超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容超长内容 </td> 
            </tr>
             </tbody> 
         </table>
    </body>
    </html
    >

    输出如下: 

     

  • 相关阅读:
    关于前台日期转换和比较大小以及今天前三天日期
    20180409和四岁淘淘探讨死亡
    [转载]谷歌浏览器Chrome下载文件时文件名乱码问题
    [转载]美国科学在线版
    [转载]学习资料-科学类
    小班的淘淘
    Spring Security构建Rest服务-0702-个性化用户认证流程2
    Spring Security构建Rest服务-0701-个性化用户认证流程
    Spring Security构建Rest服务-0700-SpringSecurity开发基于表单的认证
    Spring Security构建Rest服务-0600-SpringSecurity基本原理
  • 原文地址:https://www.cnblogs.com/xuzhudong/p/8854717.html
Copyright © 2011-2022 走看看