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


一、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"為鼠標懸停顯示的內容。
四、效果實現

 


 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM