css特效實現html表格顯示部分內容,當鼠標移上去顯示全部。

在寫網頁的時候,經常需要用表格來展示數據,但是如果其中某個td中的數據太多,就會使整個頁面不協調,如果固定了表格的寬度那麼內容又不能全部顯示出來,怎麼辦呢? 本人今天就遇到了這樣一個小問題,現將其記錄下來,留作以後需要時查看。


先上css代碼:
.newsInfo:hover {
    background: #eee;
    color: #333;
    z-index: 999;
}
.newsInfo {

    position: relative;
    z-index: 0;
}  
.newsInfo span {
	
    display: none;
} 
.newsInfo:hover span {
    display: block;
    position: absolute;
    min-width:400px;
    top: 28px;
    left:100px;
    border: 1px solid #cccccc;
    background: #C1CDC1;
    color: black;
    padding: 5px;
    text-align: left;
    overflow: hidden;
}
.newInfoTruncation {
    width:120px;
    white-space:nowrap; 
    word-break:keep-all; 
    overflow:hidden; 
    text-overflow:ellipsis;
}   

然後html代碼:

<html>
<head>
    <link href="index.css" rel="Stylesheet" type="text/css" />
</head>
<body>
    <div>
        <a href="#"class="newsInfo">
            <div class="newInfoTruncation">
                參考消息網2月29日報道 韓媒稱,中國正在迅速增強國防實力。去年年底和今年年初,中國先後採取了各種史無前例的強化軍事力量的措施。有預測稱,連續5年實現兩位數增長的中國國防預算今年的漲幅將超出以往。
            </div>
            <span>
                參考消息網2月29日報道 韓媒稱,中國正在迅速增強國防實力。去年年底和今年年初,中國先後採取了各種史無前例的強化軍事力量的措施。有預測稱,連續5年實現兩位數增長的中國國防預算今年的漲幅將超出以往。
            </span>
        </a>
    </div>
</body>
</html>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章