当前位置: 七九推 > 网络运营>服务器>Linux > table设置超出部分隐藏,鼠标移上去显示全部内容的方法

table设置超出部分隐藏,鼠标移上去显示全部内容的方法

2022年12月18日 Linux 我要评论
table内容超出宽度时隐藏并显示省略标记html中,一个表格,要达到二个条件:1、内容多了不自动换行;2、固定单元格宽度。如果内容超出,则隐藏;如 果在ie下,只是写成<table style

 table内容超出宽度时隐藏并显示省略标记

html中,一个表格,要达到二个条件:

1、内容多了不自动换行;

2、固定单元格宽度。如果内容超出,则隐藏;

如 果在ie下,只是写成<table style="table-layout:fixed; overflow:hidden;"><tr><td nowrap>则可,而在ff下则不行。兼容ie和ff的写法,应该为:<table style="table-layout:fixed;"><tr>td style="overflow:hidden;" nowrap>

3、显示省略标记,只支持ie:

text-overflow:ellipsis;

测试代码:

<style>.tbl {table-layout:fixed}.td {overflow:hidden;text-overflow:ellipsis}</style>

<table class="tbl" border=1 width=80>

<tr>

    <td width=25% class="td" nowrap>abcdefghigklmnopqrstuvwxyz 1234567890</td>

    <td class="td" nowrap><div>abcdefghigklmnopqrstuvwxyz 1234567890</div></td>

</tr>

</table>

table设置超出部分隐藏,鼠标移上去显示全部内容

核心代码

table {
    border-collapse: collapse;
    width:55em;
    table-layout:fixed;/* 只有定义了表格的布局算法为fixed,下面td的定义才能起作用。 */
}
.thead th{
    width: 63px;
    height: 25px;
    text-align: center;
}
 
table td{
    position: relative;
    /*width: 80px;*/
    height: 25px;
    text-align: center;
    font-size: 12px;
    font-weight: normal;
 
    width:100%;
    word-break:keep-all;/* 不换行 */
    white-space:nowrap;/* 不换行 */
    overflow:hidden;/* 内容超出宽度时隐藏超出部分的内容 */
    text-overflow:ellipsis;/* 当对象内文本溢出时显示省略标记(...) ;需与overflow:hidden;一起使用。*/
}
table td:hover {
    overflow: visible;  /* 鼠标放上去显示全部文字 */
}

比较适合单独的页面,去过是全站模板就不能这么用了

table表格溢出隐藏

css部分:

table{
    table-layout:fixed;
    width:100%;
    height:100%;
    border-collapse:collapse;
}
table td{
    border:1px solid #5a5858;
    overflow:hidden;
    text-overflow:ellipsis;
    white-space:nowrap;
}
.box{
    width:400px;
    height:200px;
}

html部分:

<div class="box">
    <table>
        <tr>
            <td>1111</td>
            <td>5555555555555555555456464645646464646</td>
        </tr>
    </table>
</div>

到此这篇关于table设置超出部分隐藏,鼠标移上去显示全部内容的方法的文章就介绍到这了,更多相关table超出隐藏内容请搜索七九推以前的文章或继续浏览下面的相关文章,希望大家以后多多支持七九推!

(0)
打赏 微信扫一扫 微信扫一扫

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2023  七九推 保留所有权利. 粤ICP备17035492号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com