純CSS實現(xiàn)鼠標(biāo)懸停顯示圖片效果的實例分享
haorooms 發(fā)布時間:2016-06-06 11:42:30 作者:Aaron
我要評論

這里來給大家推薦一個純CSS實現(xiàn)鼠標(biāo)懸停顯示圖片效果的實例分享,以針對鼠標(biāo)移到tr標(biāo)簽上來添加hover這種最簡單的方式來演示,簡單明了,需要的朋友可以參考下
最近在做一個網(wǎng)盤的項目,用到了鼠標(biāo)移上去效果,這個效果可以用js來實現(xiàn),今天主要分享一下,這個效果如何用純css實現(xiàn)!
效果如下圖:
html代碼
XML/HTML Code復(fù)制內(nèi)容到剪貼板
- <table id="filelist" style="width:100%;">
- <tbody>
- <tr>
- <td class="filename ui-draggable ui-droppable" width="30%;">
- <div class="name">
- <span class="fileactions">
- <a href="#" class="action action-download" data-action="Download" original-title="">
- <img class="svg" src="svg/download.svg">
- <span>下載</span>
- </a>
- <a href="#" class="action action-share permanent" data-action="Share" original-title="">
- <img class="svg" src="svg/public.svg">
- <span>已共享</span>
- </a>
- </span>
- </div>
- </td>
- <td class="filesize" style="color:rgb(-4780,-4780,-4780)">70.3 MB</td>
- <td class="date">
- <span class="modified" title="September 29, 2014 14:45" style="color:rgb(0,0,0)">2 分鐘前</span>
- <a href="#" original-title="刪除" class="action delete delete-icon"></a>
- </td>
- </tr>
- <tr >
- <td class="filename ui-draggable ui-droppable" width="30%;">
- <div class="name" >
- <span class="fileactions">
- <a href="#" class="action action-download" data-action="Download">
- <img class="svg" src="svg/download.svg">
- <span>下載</span>
- </a>
- <a href="#" class="action action-share" data-action="Share">
- <img class="svg" src="svg/share.svg">
- <span>分享</span>
- </a>
- </span>
- </div>
- </td>
- <td class="filesize" style="color:rgb(159,159,159)">762 kB</td>
- <td class="date">
- <span class="modified" style="color:rgb(0,0,0)" original-title="September 29, 2014 16:36">2 分鐘前</span>
- <a href="#" original-title="刪除" class="action delete delete-icon"></a>
- </td>
- </tr>
- </tbody>
- </table>
上面代碼我直接從項目中復(fù)制,可能有很多多余的css,大家只是看下大致代碼!
精華的css
圖片中的效果,大致的實現(xiàn)思路是,一開始設(shè)置為opacity=0,然后鼠標(biāo)移上去之后顯示。
代碼如下:
CSS Code復(fù)制內(nèi)容到剪貼板
- #filelist a.action {
- display: inline;
- padding: 18px 8px;
- line-height: 50px;
- -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
- filter: alpha(opacity=0);
- opacity: 0;
- display:none;
- }
- #filelist tr:hover a.action , #filelist a.action.permanent{
- -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
- filter: alpha(opacity=50);
- opacity: .5;
- display:inline;
- }
- #filelist tr:hover a.action:hover {
- -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
- filter: alpha(opacity=100);
- opacity: 1;
- display:inline;
- }
以上是大致的精華代碼!
css技巧分析
tr鼠標(biāo)移上去,下面的a標(biāo)簽顯示可以這么選擇 #filelist tr:hover a.action 加入tr鼠標(biāo)移上去hover了,那么tr下面的a標(biāo)簽的鼠標(biāo)移上去效果同樣有用,這么寫: #filelist tr:hover a.action:hover
jquery中有attr,活動標(biāo)簽的屬性,css也可以和jquery一樣的類似選擇。
例如下面的這個a標(biāo)簽
XML/HTML Code復(fù)制內(nèi)容到剪貼板
- <a href="#" data-action="Rename" class="action"></a>
我們可以這么寫樣式:
CSS Code復(fù)制內(nèi)容到剪貼板
- a.action[data-action="Rename"]{
- padding: 16px 14px 17px !important;
- position: relative;
- top: -21px;
- }
看了這篇文章,您有收獲嗎?不知道通過這篇文章,您對CSS有沒有更近一步的了解!
相關(guān)文章
- 這篇文章主要介紹了CSS 實現(xiàn) 圖片鼠標(biāo)懸停折疊效果,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-09-21
純CSS實現(xiàn)鼠標(biāo)懸停圖片上升顯示描述案例
當(dāng)我們想在圖片上面放置一些文字內(nèi)容時,發(fā)現(xiàn)不管怎么放置,要么就是圖片影響到文字的觀感,要么就是文字擋住圖片的細節(jié),那么怎么可以既看到圖片的細節(jié)又可以看到對圖片的2023-03-01