*初级小白*~ 2022-10-18 11:06 采纳率: 97.9%
浏览 45
已结题

html+css表格超过一定宽度显示省略号

如何让表格中的14列和15列超过120px宽度,就隐藏并显示省略号

img


<template>
  <div id="printTable">
    <div class="craftTable processScheduling">
      <div class="table_container">
        <table border="1px" cellspacing="0" class="text-center">
          <thead>
            <tr>
              <th rowspan="2">1</th>
              <th rowspan="2" class="SecondTd">2</th>
              <th rowspan="2">3</th>
              <th rowspan="2">4</th>
              <th rowspan="2">5</th>
              <th rowspan="2">6</th>
              <th rowspan="2">7</th>
              <th rowspan="2">8</th>
              <th rowspan="2" style="min-width:55px">9</th>
              <th rowspan="2" style="min-width:55px">10</th>
              <th rowspan="2">11</th>
              <th rowspan="2">12</th>
              <th rowspan="2">13</th>
              <th rowspan="2">14</th>
              <th rowspan="2">16</th>
              <th rowspan="2">17</th>
              <th rowspan="2">18</th>
              <th rowspan="2">19</th>
              <th colspan="2">20</th>
              <th rowspan="2">21</th>
              <th rowspan="2">22</th>
              <th rowspan="2" class="last_th">24</th>
            </tr>
            <tr>
              <th>12</th>
              <th>12</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="(item,index) in 100" :key="index">
              <td class="firstTd">fdsa</td>
              <td class="SecondTd">gfdg</td>
              <td>gfhfd</td>
              <td>fsdf</td>
              <td>fsaf</td>
              <td>re</td>
              <td>fsadf</td>
              <td>gsfd</td>
              <td>da</td>
              <td>hhsdh</td>
              <td>fsgda</td>
              <td>hdh</td>
              <td>hfdghfh</td>
              <td>tsadgtsadgtsadgtsadgtsadgtsadgtsadgtsadgtsadgtsadgtsadgtsadg</td>
              <td>tsadgtsadgtsadgtsadgtsadgtsadgtsadgtsadgtsadgtsadgtsadgtsadg</td>
              <td>hfghf</td>
              <td>afdgs</td>
              <td>sagsg</td>
              <td colspan="2">
                <div style="display:flex">
                  <div style="width:50%;border-right:1px solid #eee">111</div>
                  <div style="width:50%">111</div>
                </div>
              </td>
              <td>fsadfs</td>
              <td>fdfsf</td>
              <td class="last_td">fsdafas</td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>

  </div>
</template>

<script>
import { ref } from "vue";
import print from 'print-js';

export default {
  setup() {
   
    return {
    };
  },
};
</script>

<style lang="scss" scoped>
.craftTable {
  width: 100%;
  margin: auto;
  background-color: #fff;

  .table_container {
    width: 100%;
    height: calc(100vh - 110px);
    overflow: scroll;
    margin: auto;

    table {
      // table-layout: fixed;
      border: none;
      border-collapse: collapse;
      background-color: #fff;
      text-align: center;

      thead {
        position: -webkit-sticky;
        position: sticky;
        top: 0;
        z-index: 3;

        tr {
          color: #000;
          font-weight: bold;

          th {
            background-color: skyblue;
            min-width: 70px;
            border-right: 1px solid #eee;
          }

          //操作
          th.last_th {
            position: -webkit-sticky;
            position: sticky;
            right: 0;
            z-index: 4;
            border-right: none;
            min-width: 150px;
          }
        }
      }

      tbody {
        tr {
          cursor: pointer;

          td {
            min-width: 70px;
            position: -webkit-sticky;
            position: sticky;
            // word-break: break-word;
            // word-wrap: break-word;
            // white-space: nowrap;
            padding: 0px;
            border: 1px solid #eee;
            height: 30px;
          }

          td.last_td {
            background-color: rgb(142, 142, 230);
            font-weight: bold;
            right: 0;
            // z-index: 3;
            border-right: none;
          }
        }
      }

      //订单号,客户代码
      th:nth-child(14),
      td:nth-child(14),
      th:nth-child(15),
      td:nth-child(15) {
        // width: 8%;
        min-width: 120px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }

      th:nth-child(16),
      th:nth-child(19),
      th:nth-child(20),
      th:nth-child(21) {
        min-width: 200px;
      }
    }
  }

}

</style>
  • 写回答

4条回答 默认 最新

  • CSDN专家-showbo 2022-10-18 11:34
    关注

    14,15列添加一样特殊样式,设置max-width:120px就行

                  <td class="overflowdot">tsadgtsadgtsadgtsadgtsadgtsadgtsadgtsadgtsadgtsadgtsadgtsadg</td>
                  <td class="overflowdot">tsadgtsadgtsadgtsadgtsadgtsadgtsadgtsadgtsadgtsadgtsadgtsadg</td>             
    
    

    overflowdot样式

              td.overflowdot{
                max-width:120px
              }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 10月26日
  • 已采纳回答 10月18日
  • 创建了问题 10月18日

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效