1. 程式人生 > >table中td超出內容隱藏,鼠標懸停全部顯示(完整版,含js代碼)

table中td超出內容隱藏,鼠標懸停全部顯示(完整版,含js代碼)

效果 pre order 出現 fun 默認 css語法 標記 -a

一、CSS語法: text-overflow:clip | ellipsis 默認值:clip 適用於:所有元素 clip: 當對象內文本溢出時不顯示省略標記(...),而是將溢出的部分裁切掉。 ellipsis: 當對象內文本溢出時顯示省略標記(...)。 在使用的時候,有時候發現不會出現省略標記效果,經過測試發現,使用ellipsis的時候,必須配合overflow:hidden; white-space:nowrap; width:50%;這三個樣式共同使用才會有效果 實例:
table {
            width: 100%;
            float: left
; table-layout:fixed; width:500px; border:1px solid #ccc; } table tr { line-height: 25px; border:1px solid #ccc; } table td { border:1px solid #ccc; text-align
:center; } .MHover{ border:1px solid #ccc; white-space:nowrap; text-overflow:ellipsis; overflow:hidden; }
二、HTML代碼
<table>
<tr>
<th>姓名</th>
<th>個性簽名</th>
<th>
性別</th> </tr> <tr> <td>張國榮</td> <td> <div class="MHover">我就是我,是顏色不一樣的煙火!</div> <div class="MALL">我就是我,是顏色不一樣的煙火!</div> </td> <td></td> </tr> </table>
註:class="MHover"為表格裏顯示的內容,內容長度超多指定寬度時隱藏多余字段,並在後面加...   class="MALL"為鼠標懸停顯示的內容。 三、js代碼
$(document).ready(function () {
            $(".MALL").hide();
            $(".MHover").mouseover(function (e) {
                $(this).next(".MALL").css({"position":"absolute","top":e.pageY+5,"left":e.pageX+5}).show();
            });
            $(".MHover").mousemove(function (e) {
                $(this).next(".MALL").css({ "color": "fff", "position": "absolute", "opacity": "0.7", "background-color": "666", "top": e.pageY + 5, "left": e.pageX + 5 });
            });
            $(".MHover").mouseout(function () {
                $(this).next(".MALL").hide();
            });
        });
註:class="MHover"為表格裏顯示的內容,內容長度超多指定寬度時隱藏多余字段,並在後面加...   class="MALL"為鼠標懸停顯示的內容。

table中td超出內容隱藏,鼠標懸停全部顯示(完整版,含js代碼)