CSS教程

关注公众号 jb51net

关闭
网页制作 > CSS > CSS教程 >

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

追丰少年

 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超出隐藏内容请搜索脚本之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持脚本之家!