zoukankan      html  css  js  c++  java
  • Html table 内容超出显示省略号

    内容超出显示省略号:

    <html>
    <style>
        table {
            table-layout: fixed;
            width: 100%;
        }
        table, th, td {
            border: 1px solid #999;
            padding: 5px;
            text-align: left;
        }
        td.desc {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
    
    <table>
      <thead>
        <tr>
          <th class="desc">项目名</th>
          <th width='20%' class="desc">Url</th>
          <th width='40%' class="desc">描述</th>
          <th>语言</th>
          <th class="number desc">Stars</th>
        </tr>
      </thead>
      <tbody>
      {% for source in sources %}
        <tr>
          <td class="desc" title="{{ source.name }}">{{ source.name }}</td>
          <td class="desc" title="{{ source.url }}">{{ source.url }}</td>
          <td class="desc" title="{{ source.description }}">{{ source.description }}</td>
          <td class="desc" title="{{ source.primary_lang }}">{{ source.primary_lang }}</td>
          <td>{{ source.stars }}</td>
        </tr>
      {% endfor %}
      </tbody>
    </table>
    </html>
     
    View Code

    注意:

    1、 table 设置:

           table-layout:fixed; /* 只有定义了表格的布局算法为fixed,下面td的定义才能起作用。 */

           table的width 也要设置;

    2、th, td 的设置:

          overflow:hidden; /* 内容超出宽度时隐藏超出部分的内容 */

          text-overflow:ellipsis; /* 当对象内文本溢出时显示省略标记(...) ;需与overflow:hidden;一起使用。*/

    3、这些样式必须在 th, td 都写才有效果,并且th, td 还要定义属性width。

    另外,省略的文字如果想展示,

    可以给td添加title属性,这样鼠标移动到该元素会自动显示所有的文字。

  • 相关阅读:
    Oracle数据库实例的启动及关闭
    SCJP之赋值
    fileupload组件之上传与下载的页面
    commons-fileupload-1.2.1.jar 插件上传与下载
    SCJP读书之知识点:
    filter
    抽象abstract
    搞定导致CPU爆满的“罪魁祸首”
    优化一个小时不出结果的SQL
    最具戏剧性的分析诊断案例——十分钟锁定数据库性能“元凶”
  • 原文地址:https://www.cnblogs.com/langxing/p/11686939.html
Copyright © 2011-2022 走看看