首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >文本溢出:省略号移除字体令人敬畏的图标

文本溢出:省略号移除字体令人敬畏的图标
EN

Stack Overflow用户
提问于 2017-11-02 11:04:37
回答 3查看 1.4K关注 0票数 9

我有一张简单的桌子,里面有字体很棒的图标。我使用普通的javascript使表列可调整大小。如果单元格内容被覆盖并省略(“.”),则该单元格内容被隐藏。所示如下:

代码语言:javascript
复制
td, th {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

问题:当调整列大小以便隐藏内容并使其再次变大时,除了第一个图标之外,所有图标都消失了。

预期的行为:当使列再次变大时,图标应该重新出现。

请运行下面的代码片段以查看它的运行情况。任何帮助都非常感谢!谢谢。

代码语言:javascript
复制
(function makeTableHeaderResizable() {
  // clear resizers
  Array.prototype.forEach.call(
    document.querySelectorAll('.table-resize-handle'),
    function(elem) {
      elem.parentNode.removeChild(elem);
    }
  );

	// create resizers
  var thElm;
  var startOffset;
  Array.prototype.forEach.call(
    document.querySelectorAll('table th'),
    function(th) {
      th.style.position = 'relative';

      var grip = document.createElement('div');
      grip.innerHTML = ' ';
      grip.style.top = 0;
      grip.style.right = 0;
      grip.style.bottom = 0;
      grip.style.width = '5px';
      grip.style.position = 'absolute';
      grip.style.cursor = 'col-resize';
      grip.className = 'table-resize-handle';
      grip.addEventListener('mousedown', function(e) {
        thElm = th;
        startOffset = th.offsetWidth - e.pageX;
      });

      th.appendChild(grip);
    }
  );

  document.addEventListener('mousemove', function(e) {
    if (thElm) {
      thElm.style.width = startOffset + e.pageX + 'px';
    }
  });

  document.addEventListener('mouseup', function() {
    thElm = undefined;
  });
})();
代码语言:javascript
复制
/* text-overflow: ellipsis is likely causing the issue here */
td, th {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
table {
  table-layout: fixed;
  border-top: 1px solid black;
  width: 100%;
}

/* styling */
th {
  border-right: 1px dotted red;
}
th {
  height: 50px;
}
td {
  border: 1px solid black;
}
tr {
  border-left: 1px solid black;
}
代码语言:javascript
复制
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<h5>Drag the right border of the th elements and make the cells smaller. All fa-icons but the first have disappeared when you make the cells wider again.</h5>
<table>
  <thead>
    <tr>
      <th>Column</th>
      <th>Column</th>
      <th>Column</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>
        text works normally
      </td>
      <td>
        <i class="fa fa-cog"></i>
        <i class="fa fa-edit"></i>
        <i class="fa fa-trash"></i>
        <i class="fa fa-check"></i>
      </td>
      <td>
        <i class="fa fa-cog"></i>
        <i class="fa fa-edit"></i>
        <i class="fa fa-trash"></i>
        <i class="fa fa-check"></i>
      </td>
    </tr>
  </tbody>
</table>

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-11-02 12:52:15

您可以将fa类的fa属性设置为inline (工作小提琴这里):

代码语言:javascript
复制
td .fa {
  display: inline !important;
}
票数 1
EN

Stack Overflow用户

发布于 2017-11-02 11:28:46

尝试用这个css,给宽度100%表或一些最大宽度。

代码语言:javascript
复制
 td, th {
    white-space: -o-pre-wrap; 
    word-wrap: break-word;
    white-space: pre-wrap; 
    white-space: -moz-pre-wrap; 
    white-space: -pre-wrap; 
}
票数 1
EN

Stack Overflow用户

发布于 2017-11-02 11:31:01

只需在display中取消fa类的td属性。

代码语言:javascript
复制
.fa {
   display: inline-block;
}

为了拥有

代码语言:javascript
复制
.fa {
  display: unset;
}

喜欢

代码语言:javascript
复制
/* Remove default inline-block of font awesome .fa class */
td i {
  display: unset !important;
}

下面是一个有用的例子。

代码语言:javascript
复制
(function makeTableHeaderResizable() {
  // clear resizers
  Array.prototype.forEach.call(
    document.querySelectorAll('.table-resize-handle'),
    function(elem) {
      elem.parentNode.removeChild(elem);
    }
  );

  // create resizers
  var thElm;
  var startOffset;
  Array.prototype.forEach.call(
    document.querySelectorAll('table th'),
    function(th) {
      th.style.position = 'relative';

      var grip = document.createElement('div');
      grip.innerHTML = '&nbsp;';
      grip.style.top = 0;
      grip.style.right = 0;
      grip.style.bottom = 0;
      grip.style.width = '5px';
      grip.style.position = 'absolute';
      grip.style.cursor = 'col-resize';
      grip.className = 'table-resize-handle';
      grip.addEventListener('mousedown', function(e) {
        thElm = th;
        startOffset = th.offsetWidth - e.pageX;
      });

      th.appendChild(grip);
    }
  );

  document.addEventListener('mousemove', function(e) {
    if (thElm) {
      thElm.style.width = startOffset + e.pageX + 'px';
    }
  });

  document.addEventListener('mouseup', function() {
    thElm = undefined;
  });
})();
代码语言:javascript
复制
/* text-overflow: ellipsis is likely causing the issue here */

td,
th {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

table {
  table-layout: fixed;
  border-top: 1px solid black;
  width: 100%;
}


/* styling */

th {
  border-right: 1px dotted red;
}

th {
  height: 50px;
}

td {
  border: 1px solid black;
}

tr {
  border-left: 1px solid black;
}


/* Remove default inline-block of font awesome .fa class */

td i {
  display: unset !important;
}
代码语言:javascript
复制
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<h5>Drag the right border of the th elements and make the cells smaller. All fa-icons but the first have disappeared when you make the cells wider again.</h5>
<table>
  <thead>
    <tr>
      <th>Column</th>
      <th>Column</th>
      <th>Column</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>
        text works normally
      </td>
      <td>
        <i class="fa fa-cog"></i>
        <i class="fa fa-edit"></i>
        <i class="fa fa-trash"></i>
        <i class="fa fa-check"></i>
      </td>
      <td>
        <i class="fa fa-cog"></i>
        <i class="fa fa-edit"></i>
        <i class="fa fa-trash"></i>
        <i class="fa fa-check"></i>
      </td>
    </tr>
  </tbody>
</table>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47073744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档