CSS3实现鼠标悬停显示扩展内容
建站知识 2021-07-03 08:15www.168986.cn长沙网站建设
我们在做导航标签的时候,有时会出现空间过于拥挤需要隐藏部分内容的情况,所以在这里我自己写了一个鼠标悬停显示扩展内容的效果,如下图所示。
效果还是比较好实现,比较头疼的是三角部分使用了伪元素::after,而对父元素设置 over-flow:hidden 时也会把伪元素给隐藏掉。想的办法是把文字和图标用一个 <span> 包裹住然后对其设置over-flow属性。
HTML代码
CSS Code复制内容到剪贴板
- <div id="nav">
- <a id="nav-main"><span><i class="icon-home"></i> 主界面</span></a>
- <a id="nav-sum"><span><i class="icon-lap"></i> 统计界面</span></a>
- </div>
- CSS代码
- //
- / nav /
- //
- #nav{
- box-sizing:border-box;
- width:200px;
- height:100%;
- position:fixed;
- padding-:80px;
- }
- #nav a{
- display:block;
- width:30px;
- height:52px;
- position:relative;
- margin-:50px;
- }
- #nav a span{
- display:inline-block;
- width:46px;
- height:50px;
- font-size:1em;
- font-weight:600;
- color:rgba(255,255,255,0.9);
- text-indent:3px;
- line-height:52px;
- cursor:pointer;
- overflow:hidden;
- }
- #nav a span i{
- font-size:1.3em;
- }
- #nav a::after{
- content:'';
- display:block;
- width:0;
- height:0;
- position:absolute;
- rightright:-32px;
- bottombottom:0;
- border-:26px solid transparent;
- border-right:16px solid transparent;
- border-bottom:26px solid transparent;
- }
- #nav-main{
- background-color:rgb(211,83,80);
- }
- #nav-sum{
- background-color:rgb(0,158,163);
- }
- #nav-main::after{
- border-left:16px solid rgb(211,83,80);
- }
- #nav-sum::after{
- border-left:16px solid rgb(0,158,163);
- }
- #nav a:hover{
- -webkit-animation:extend-a 0.5s;
- -moz-animation:extend-a 0.5s;
- animation:extend-a 0.5s;
- width:100px;
- }
- #nav a span:hover{
- -webkit-animation:extend-span 0.5s;
- -moz-animation:extend-span 0.5s;
- animation:extend-span 0.5s;
- width:116px;
- }
- / a扩展效果 /
- @-webkit-keyframes extend-a{
- 0% {
- width:30px;
- }
- 100% {
- width:100px;
- }
- }
- @-moz-keyframes extend-a{
- 0% {
- width:30px;
- }
- 100% {
- width:100px;
- }
- }
- @keyframes extend-a{
- 0% {
- width:30px;
- }
- 100% {
- width:100px;
- }
- }
- / span扩展效果 /
- @-webkit-keyframes extend-span{
- 0% {
- width:46px;
- }
- 100% {
- width:116px;
- }
- }
- @-moz-keyframes extend-span{
- 0% {
- width:46px;
- }
- 100% {
- width:116px;
- }
- }
- @keyframes extend-span{
- 0% {
- width:46px;
- }
- 100% {
- width:116px;
- }
- }
其中图标使用的是 font-awesome 提供的API,使用时引入它的css文件即可。
以上所述是长沙网络推广给大家介绍的CSS3实现鼠标悬停显示扩展内容 ,希望对大家有所帮助,如果大家有任何疑问请给我留言,长沙网络推广会及时回复大家的。在此也非常感谢大家对狼蚁SEO网站的支持!
长沙网站设计
- 如何进行东阳SEO关键词优化?
- 边坝哪有关键词排名优化:提升你的网站流量与
- 安国百度优化服务:提升您的在线可见性
- 阜康新手做SEO怎么做
- 山西seo网站排名关键词优化:提升您网站曝光率
- 临沂seo网站排名关键词优化:提高你的网站可见
- 广西SEO网站推广怎样付费比较合理
- 双辽SEO网站推广:提升你的网站可见性与流量
- 辽宁企业网站优化购买方式有哪些
- 提升宝清百度SEO排名的实用技巧与策略
- 静宁百度SEO排名:提升您网站曝光率的关键策略
- 彭州百度SEO排名的提升策略和实施指南
- 广南百度关键词SEO:提升网站排名的关键策略
- 辽宁关键词优化怎么做论坛营销
- 吉林百度seo排名如何做到让用户满意
- 内黄百度优化服务:提升在线可见性的关键