国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > CSS > 正文

CSS3實現(xiàn)鼠標懸停顯示擴展內容

2024-07-11 08:32:31
字體:
來源:轉載
供稿:網(wǎng)友

我們在做導航標簽的時候,有時會出現(xiàn)空間過于擁擠需要隱藏部分內容的情況,所以在這里我自己寫了一個鼠標懸停顯示擴展內容的效果,如下圖所示。
 


總的來說效果還是比較好實現(xiàn),但是比較頭疼的是三角部分使用了偽元素::after,而對父元素設置 over-flow:hidden 時也會把偽元素給隱藏掉。最后想的辦法是把文字和圖標用一個 <span> 包裹住然后對其設置over-flow屬性。

HTML代碼:

CSS Code復制內容到剪貼板
  1.     <div id="nav">           <a id="nav-main"><span><i class="icon-home"></i> 主界面</span></a>   
  2.          <a id="nav-sum"><span><i class="icon-laptop"></i> 統(tǒng)計界面</span></a>       </div>    
  3.    CSS代碼:   
  4.    /*******************************************************************************/  
  5. /*********************************** nav **************************************/   /*******************************************************************************/  
  6. #nav{        box-sizing:border-box;   
  7.     width:200px;        height:100%;   
  8.     position:fixed;        padding-top:80px;   
  9. }    #nav a{   
  10.     display:block;        width:30px;   
  11.     height:52px;        position:relative;   
  12.     margin-top:50px;    }   
  13. #nav a span{        display:inline-block;   
  14.     width:46px;        height:50px;   
  15.     font-size:1em;        font-weight:600;   
  16.     color:rgba(255,255,255,0.9);        text-indent:3px;   
  17.     line-height:52px;        cursor:pointer;   
  18.     overflow:hidden;    }   
  19. #nav a span i{        font-size:1.3em;   
  20. }    #nav a::after{   
  21.     content:'';        display:block;   
  22.     width:0;        height:0;   
  23.     position:absolute;        rightright:-32px;   
  24.     bottombottom:0;        border-top:26px solid transparent;   
  25.     border-right:16px solid transparent;        border-bottom:26px solid transparent;   
  26. }    #nav-main{   
  27.     background-color:rgb(211,83,80);    }   
  28. #nav-sum{        background-color:rgb(0,158,163);   
  29. }    #nav-main::after{   
  30.     border-left:16px solid rgb(211,83,80);    }   
  31. #nav-sum::after{        border-left:16px solid rgb(0,158,163);   
  32. }    #nav a:hover{   
  33.     -webkit-animation:extend-a 0.5s;        -moz-animation:extend-a 0.5s;   
  34.     animation:extend-a 0.5s;        width:100px;   
  35. }    #nav a span:hover{   
  36.     -webkit-animation:extend-span 0.5s;        -moz-animation:extend-span 0.5s;   
  37.     animation:extend-span 0.5s;        width:116px;   
  38. }    /******************* a擴展效果 ******************/  
  39. @-webkit-keyframes extend-a{        0% {   
  40.         width:30px;        }   
  41.     100% {            width:100px;   
  42.     }    }   
  43. @-moz-keyframes extend-a{        0% {   
  44.         width:30px;        }   
  45.     100% {            width:100px;   
  46.     }    }   
  47. @keyframes extend-a{        0% {   
  48.         width:30px;        }   
  49.     100% {            width:100px;   
  50.     }    }   
  51. /******************* span擴展效果 ******************/   @-webkit-keyframes extend-span{   
  52.     0% {            width:46px;   
  53.     }        100% {   
  54.         width:116px;        }   
  55. }    @-moz-keyframes extend-span{   
  56.     0% {            width:46px;   
  57.     }        100% {   
  58.         width:116px;        }   
  59. }    @keyframes extend-span{   
  60.     0% {            width:46px;   
  61.     }        100% {   
  62.         width:116px;        }   
  63. }  
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 清徐县| 广东省| 长治县| 南充市| 城口县| 屯留县| 武乡县| 阿巴嘎旗| 无棣县| 周宁县| 喀什市| 建平县| 彭泽县| 清原| 从江县| 米林县| 罗城| 鹤山市| 固阳县| 东城区| 息烽县| 炎陵县| 满城县| 长宁县| 宿州市| 斗六市| 蒙阴县| 剑河县| 改则县| 任丘市| 邵武市| 万盛区| 扎囊县| 陆川县| 南昌市| 志丹县| 苍南县| 临湘市| 资源县| 德昌县| 根河市|