web前端|css教程
css,css3,html,html5,前端
web前端-css教程
本篇文章给大家带来的内容是关于如何使用纯CSS实现从按钮两侧滑入装饰元素的悬停特效(附源码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
公众号对接电影php源码,ubuntu虚拟域名配置,tomcat是电脑自带的吗,爬虫潘家园,php中什么是盒子,非正经seolzw
效果预览
收录最好的源码,ubuntu怎么进去终端,tomcat主配置文件解读,电影1爬虫,安全设置php版本如何升级,台州seo手段lzw
仿爱淘宝网站源码,ubuntu静态ip失效,python爬虫爬文字,php $@,21天seolzw
源代码下载
/comehope/front-end-daily-challenges
代码解读
定义 dom,容器是一个无序列表,列表项代表按钮:
home
居中显示:
body { margin: 0; height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(deepskyblue, navy);}
去掉列表项前面的符号:
ul { padding: 0; list-style-type: none;}
设置按钮的文字样式:
ul li { color: #ddd; font-size: 25px; font-family: sans-serif; text-transform: uppercase;}
用伪元素在按钮的左侧增加一个方块:
ul li { position: relative;}ul li::before { content: \; position: absolute; width: 100%; height: 100%; background: tomato; left: -100%;}
用伪元素在按钮的右侧增加一条下划线:
ul li::after { content: \; position: absolute; width: 100%; height: 0.2em; background: tomato; bottom: 0; left: 100%;}
接下来设置鼠标悬停效果。
当鼠标悬停时,左侧的方块移到文字所在位置:
ul li::before { transition: 0.4s ease-out;}ul li:hover::before { left: 100%;}
右侧的下划线移到文字所在位置,它的动画时间延迟到方块的动画快结束时再开始:
ul li::after { transition: 0.3s 0.3s ease-out;}ul li:hover::after { left: 0%;}
同时,提高文字的亮度:
ul li { transition: 0.3s; cursor: pointer;}ul li:hover { color: #fff;}
隐藏掉按钮外的部分,使方块和下划线在默认状态下都不可见,只有鼠标悬停时它们才从两侧入场:
ul li { overflow: hidden;}
最后,在 dom 中再增加几个按钮:
home products services contact
布局多个按钮:
ul { display: flex; flex-direction: column; align-items: center;}ul li { margin: 0.5em;}
大功告成!
更多炫酷CSS3、javascript特效代码,尽在:javascript特效大全