如何在Bootstrap响应表中使用省略号

锡巴斯佩奇

在响应表text-overflow:ellipsis中,当数据增加时th(随着col-xs-2宽度增加),该不起作用

在此处输入图片说明

代码如下:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

<div class="table-responsive">
  <table class="table">
    <thead>
      <tr>
        <th class="col-xs-2" style="text-overflow: ellipsis;">Lorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem Ipsum</th>
        <th class="col-xs-1">Firstname</th>
        <th class="col-xs-1"> Lastname</th>
        <th class="col-xs-4">Age</th>
        <th class="col-xs-2">City</th>
        <th class="col-xs-2">Country</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>1</td>
        <td>Anna</td>
        <td>Pitt</td>
        <td>35</td>
        <td>New York</td>
        <td>USA</td>
      </tr>
    </tbody>
  </table>
</div>

小羊羔

text-overflow属性仅影响沿其内联进度方向MDN溢出了块容器元素的内容

为了text-overflow工作,text-overflow: ellipsis单独指定不会有什么好处-您应该同时使用以下样式:

overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;

span, div, th, td {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  max-width: 100px;
}
<span>Inline element overflow ellipsis do not work</span>
<div>Block elements overflow ellipsis works</div>
<table>
  <tr><th>Table - Overflow test</th></tr>
  <tr><td>This is a long text</td><td>This is a long text</td></tr>
</table>

表布局中的文本溢出

因此,text-overflow适用于block元素,但是td是一个table-cell元素-表始终棘手的处理,因为他们使用的渲染默认表格布局算法调整表格及其单元格的宽度以适合其内容。

  1. 通常,指定用于获取省略号的常规属性可能会起作用:

    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    
  2. 如果它们不起作用,或者您开始​​发现表算法对您有欺骗作用,那么您可以将它们与max-width: 0

    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    max-width: 0;
    

    .table .text {
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      max-width: 0;
    }
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
      <div class="table-responsive">
        <table class="table">
          <thead>
            <tr>
              <th class="col-xs-2 text">
              Lorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem Ipsum
              </th>
              <th class="col-xs-1">Firstname</th>
              <th class="col-xs-1">Lastname</th>
              <th class="col-xs-4">Age</th>
              <th class="col-xs-2">City</th>
              <th class="col-xs-2">Country</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>1</td>
              <td>Anna</td>
              <td>Pitt</td>
              <td>35</td>
              <td>New York</td>
              <td>USA</td>
            </tr>
          </tbody>
        </table>
      </div>

  3. 另一个技巧是将文本伪元素一起包装在一起放置的span位置absolutetdwidth: 100%inline-block

    .table .text {
      position: relative;
    }
    
    .table .text span {
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      position: absolute;
      width: 100%;
    }
    
    .text:before {
      content: '';
      display: inline-block;
    }
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
      <div class="table-responsive">
        <table class="table">
          <thead>
            <tr>
              <th class="col-xs-2 text">
                <span>
              Lorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem Ipsum</span>
              </th>
              <th class="col-xs-1">Firstname</th>
              <th class="col-xs-1">Lastname</th>
              <th class="col-xs-4">Age</th>
              <th class="col-xs-2">City</th>
              <th class="col-xs-2">Country</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>1</td>
              <td>Anna</td>
              <td>Pitt</td>
              <td>35</td>
              <td>New York</td>
              <td>USA</td>
            </tr>
          </tbody>
        </table>
      </div>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在Android TextView中使用自定义省略号

来自分类Dev

R:如何在省略号中使用列表元素(如参数)?

来自分类Dev

如何在Angular中使用省略号和标签实现(动态宽度)文本输入?

来自分类Dev

在 Java 中使用省略号时如何传递数组?

来自分类Dev

BootStrap表文本省略号不能与响应式Web一起使用吗?

来自分类Dev

如何在嵌套函数中正确使用省略号

来自分类Dev

R在call()中使用省略号...

来自分类Dev

在表格中使用省略号

来自分类Dev

如何使用文字溢出:省略号?

来自分类Dev

在定义中使用省略号时,如何在R函数调用中捕获错误或未定义的参数

来自分类Dev

如何理解“包含省略号的抽象声明符只能在参数声明中使用”

来自分类Dev

Makefile.am中使用的省略号(...)是什么?

来自分类Dev

如何在R中将list()转换为省略号?

来自分类Dev

如何在标签或textbloxk的内容的中心放置省略号

来自分类Dev

如何在R中将list()转换为省略号?

来自分类Dev

如何使用CSS实现单行省略号

来自分类Dev

如何为TD设置省略号

来自分类Dev

如何避免Dplyr中的省略号...?

来自分类Dev

使用椭圆或省略号出错

来自分类Dev

处理省略号

来自分类Dev

结构省略号

来自分类Dev

当我在Google Chrome中使用省略号inContent可编辑Div时缺少文本

来自分类Dev

在引导面板标题中使用带div和span的省略号

来自分类Dev

嵌套函数中的省略号扩展:错误“'...'在错误的上下文中使用”

来自分类Dev

通过网址中的URI代码在推文中使用省略号?

来自分类Dev

未公开代码时的编译和执行;在代码中使用省略号

来自分类Dev

使用Bootstrap添加边框后,圆形按钮变为省略号

来自分类Dev

如何将数据表省略号应用于此列?

来自分类Dev

如何用省略号截断长文本,但总是在省略号后显示图标

Related 相关文章

  1. 1

    如何在Android TextView中使用自定义省略号

  2. 2

    R:如何在省略号中使用列表元素(如参数)?

  3. 3

    如何在Angular中使用省略号和标签实现(动态宽度)文本输入?

  4. 4

    在 Java 中使用省略号时如何传递数组?

  5. 5

    BootStrap表文本省略号不能与响应式Web一起使用吗?

  6. 6

    如何在嵌套函数中正确使用省略号

  7. 7

    R在call()中使用省略号...

  8. 8

    在表格中使用省略号

  9. 9

    如何使用文字溢出:省略号?

  10. 10

    在定义中使用省略号时,如何在R函数调用中捕获错误或未定义的参数

  11. 11

    如何理解“包含省略号的抽象声明符只能在参数声明中使用”

  12. 12

    Makefile.am中使用的省略号(...)是什么?

  13. 13

    如何在R中将list()转换为省略号?

  14. 14

    如何在标签或textbloxk的内容的中心放置省略号

  15. 15

    如何在R中将list()转换为省略号?

  16. 16

    如何使用CSS实现单行省略号

  17. 17

    如何为TD设置省略号

  18. 18

    如何避免Dplyr中的省略号...?

  19. 19

    使用椭圆或省略号出错

  20. 20

    处理省略号

  21. 21

    结构省略号

  22. 22

    当我在Google Chrome中使用省略号inContent可编辑Div时缺少文本

  23. 23

    在引导面板标题中使用带div和span的省略号

  24. 24

    嵌套函数中的省略号扩展:错误“'...'在错误的上下文中使用”

  25. 25

    通过网址中的URI代码在推文中使用省略号?

  26. 26

    未公开代码时的编译和执行;在代码中使用省略号

  27. 27

    使用Bootstrap添加边框后,圆形按钮变为省略号

  28. 28

    如何将数据表省略号应用于此列?

  29. 29

    如何用省略号截断长文本,但总是在省略号后显示图标

热门标签

归档