html - 在 Bootstrap 中截断长链接

标签 html css twitter-bootstrap

我正在使用 Bootstrap 3.1 设计一个页面,如果 HTML 链接的长度太长,它就会溢出并在移动版本中创建水平滚动。有没有办法截断它并用省略号替换它?

例子:

enter image description here

我需要的是,它应该在边界之前被截断,而不是向外延伸。知道怎么做吗?

最佳答案

您需要确保容器具有overflow: hidden 以防止文本流出边界并给它text-overflow: ellipsis 以提供链接省略号。

.box {
  background: #f99;
  border: 1px solid #c66;
  width: 100px;
  padding: 7px;
  margin-bottom: 15px;
}

.nowrap {
  white-space: nowrap;
}


.ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
}
<div class="box">
  <span class="nowrap">A really long piece of text</span>
</div>

<div class="box ellipsis">
  <span class="nowrap">A really long piece of text</span>
</div>

关于html - 在 Bootstrap 中截断长链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28126347/

相关文章:

css - 我如何选择 .class-a :nth-child only when it also has class . class-b

javascript - 如何显示没有按钮的消息框,并在指定时间后消失?

css - 如何根据屏幕尺寸对列进行排序?

html - 如何从 Bootstrap 中的选择框组件中删除边框半径

jquery - 如何使用 jQuery append()(以正确的顺序)执行大量的 DOM 插入?

javascript - 使用正则表达式删除前导空格、回车符和不需要的标签

Html 到 FOP 与 XSLT : css class to attribute-set

html - 通过示例使用 bootstrap 制作响应式登录表单。添加文本后如何使表单标签过渡保持不变?

javascript - 循环 JSON 结果并相应地设置 div html

html - 如何在 RTL 页面中显示 Bootstrap 按钮组?