简体   繁体   English

如何使锚标签字内的文本被空格包裹?

[英]How to make text inside anchor tag word wrapped ,by space?

I have applied the following CSS to a table:我已将以下 CSS 应用于表:

td {
    overflow: hidden;
    white-space: pre-wrap;
    text-overflow: ellipsis;
}

the table html is something like this:表 html 是这样的:

<tbody>
  <tr ng-repeat="a in vm.listOfA" id="{{ request._links.self.href }}" ng-click="vm.setSelected(request)" ng-class="{ warning: (vm.selectedRequest !== null  && vm.selectedRequest._links.self.href === request._links.self.href) }">
    <td ng-repeat="column in vm.availableColumns" ng-if="vm.selectedColumns.indexOf(column.name)!=-1">
      <span ng-show="!column.isAnchor">{{ request[column.name] }} </span>
      <a ng-show="column.isAnchor" ng-href="{{ vm.jumpTo(request._links.myLink.href) }}">{{ request[column.name] }} </a>
    </td>
</tbody>

and this wraps up the content of all cells by word, ie.这将按单词包装所有单元格的内容,即。 the text goes to new line on white space.文本转到空白处的新行。 But for some reason it doesn't apply to a anchor tag inside the td and the word in the link gets broken to reach new line.But, I need to show each individual word in the link text in new line.但是由于某种原因,它不适用于 td 内的锚标记,并且链接中的单词被破坏以到达新行。但是,我需要在新行中显示链接文本中的每个单词。 I am pretty new to css and html, and in my project I am using bootstrap and angular js.我对 css 和 html 很陌生,在我的项目中,我使用的是引导程序和 angular js。 Why is this happening and what is the work-around for this?为什么会发生这种情况,解决方法是什么?

EDIT 1: it seems the formatting is applied on the a tag as well, unlike what I thought at first, but the problem is it contains text with '-' and the new line is applied on the '-' instead of the white space, how do I make the new line to work only when white space is encountered?编辑1:似乎格式也应用于a标签,这与我最初的想法不同,但问题是它包含带有'-'的文本,并且新行应用于'-'而不是空白,如何使新行仅在遇到空白时才起作用?

found the solution, it seems the word wrap by default breaks line by hyphen,so replacing the hyphen with a non-breaking hyphen solved the problem for me.找到了解决方案,似乎默认情况下自动换行由连字符换行,因此用非中断连字符替换连字符为我解决了这个问题。

request[i].anchorText = request[i].anchorText.replace(/-/g, '‑');

reference- https://stackoverflow.com/a/43619683/11259999参考- https://stackoverflow.com/a/43619683/11259999

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM