javascript - Bootstrap 工具提示在内容较大的表格单元格中偏离中心

标签 javascript html css twitter-bootstrap

我有一个表格,其中一些单元格包含链接。这些链接中的文本可能很长。隐藏表格单元格的溢出,因此所有单元格的宽度都相同。当我在标签上放置 Bootstrap 工具提示时,这会导致问题,因为工具提示向右移动到链接文本的隐藏宽度的中心。

这是一个演示我的问题的 fiddle :http://jsfiddle.net/zjy1t9s7/

<table class="table table-condensed table-hover">
    <tbody>
        <tr>
            <td >
                <a data-original-title="666" data-toggle="tooltip" data-placement="bottom" title="">
                    This link has an incredibly long text which shifts the entire tooltip outside of the table cell, I personally think this looks like shit and want to fix it. Let's see if I can reproduce it here.
                </a>
            </td>
                                                                                         <td >
                <a data-original-title="555" data-toggle="tooltip" data-placement="bottom" title="">
                    These are not as big
                </a>
            </td>
            <td >
                <a data-original-title="555" data-toggle="tooltip" data-placement="bottom" title="">
                    These are not as big
                </a>
            </td>
                                                                                          <td >
                <a data-original-title="555" data-toggle="tooltip" data-placement="bottom" title="">
                    These are not as big
                </a>
            </td>
        </tr>
    </tbody>
</table>

td {
    border:1px solid #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 75px;
}

将鼠标悬停在第一个表格单元格上,看看我的意思。

这个可以修复吗?

最佳答案

我尝试的第一件事是将工具提示信息添加到 td 标签。但这引起了一个小问题,所以我在它周围添加了一个 div-wrapper,这对我很有用:

<td >
    <div data-original-title="666" data-toggle="tooltip" data-placement="bottom" title="">
        <a>
        This link has an incredibly long text which shifts the entire tooltip outside of the table cell, I personally think this looks like shit and want to fix it. Let's see if I can reproduce it here.
        </a>
    </div>
</td>

添加CSS:

td > div {
    max-width: 100%;
    overflow:hidden;
    text-overflow:ellipsis;
}

fiddle :https://jsfiddle.net/zjy1t9s7/1/

编辑:没有 div-wrapper 的更简单的解决方案

将此添加到您的 CSS 中:

td > a {
    display:inline-block;
    max-width:100%;
    overflow:hidden;
    text-overflow:ellipsis;
}

等文本标签需要定义为 block 类型显示样式,如果你想指定一个宽度或使用padding

fiddle :http://jsfiddle.net/zjy1t9s7/2/

关于javascript - Bootstrap 工具提示在内容较大的表格单元格中偏离中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33216854/

相关文章:

javascript - 单击 div 后通过 jquery 更改 css

javascript - jQuery - 将标签和复选框组限制为最大数量

javascript - 嵌套 Javascript 对象的 Swift 版本

css - 如何在同一行排列 3 个 div?

javascript - 获取 touchstart 事件中的元素位置

javascript - 对多个组合框使用相同的 ID?

javascript - Vue.js 破坏了 Google map 功能

ipad - 保存图像以供离线使用 html 5 网络应用程序

html - 在移动浏览器中,页脚图像不会重复,但背景图像会重复并且很好

html - 导航栏不会覆盖顶部 slider