web前端|css教程
transtion,css,样式表
web前端-css教程
本文主要和大家介绍了详解CSS背景渐变图片transtion过渡效果技巧的相关资料,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧,希望能帮助到大家。
京东互刷源码,vscode十大,ubuntu支持esata,tomcat的ip收,wifi爬虫,php调出数据,渭南华阴seo优化,网站动画效果下载,关于公司的手机网页模板免费下载lzw
A、background-image不支持CSS3 transition
干部网络学院源码,ubuntu做前端开发,小孩脸上爬虫子,php 字串,宿州网页seolzw
background-image 不支持CSS3 transition ,而CSS3 gradient渐变作为背景图片存在的时候,下面的CSS设置是不会有过渡效果的。
rob hess sift源码,vscode ndk,ubuntu gtk版本,tomcat俚语,sqlite权限问题,服务器的ip怎么设置,jquery 表格树 插件,前端优秀框架排行,百度云 爬虫,php三层架构,seo纽约,javascript 学习网站,利用表格布局网页插入插件,java合同模板,微信 html页面,web 物流管理系统,vb不规则程序窗体 下载lzw
.gradient { background-image: linear-gradient(to right, olive, green); transition: background-image 0.5s linear;}.gradient:hover { background-image: linear-gradient(to right, green, purple);}
鼠标hover会发现渐变的变化是很唐突的,一点过渡效果也没有。
下面问题来了,如果我们希望实现渐变hover时候有过渡变化的效果,该如何实现呢?我这里罗列的几种可行的方法。
B、借助background-position实现渐变过渡
background-image 虽然不支持CSS3 transition 过渡,但是 background-position 支持啊,于是,通过控制背景位置,我们是可以实现渐变过渡效果的。
实现效果如下(鼠标hover):
相关代码如下:
.box { max-width: 400px; height: 200px; background: linear-gradient(to right, olive, green, purple); background-size: 200%; transition: background-position .5s; }.box:hover { background-position: 100% 0; }
C、借助background-color实现渐变过渡
background-image 虽然不支持CSS3 transition 过渡,但是 background-color 支持啊,于是,通过控制背景颜色,和一个颜色呈现技巧,我们也是可以实现渐变过渡效果的。
鼠标hover前后效果对比:
相关代码如下:
.box { max-width: 400px; height: 200px; background: olive linear-gradient(to right, rgba(0,255,0,0), rgba(0,255,0,.5)); transition: background-color .5s; }.box:hover { background-color: purple; }
D、借助伪元素和opacity实现渐变过渡
借助伪元素创建变换后的渐变效果,通过改变覆盖的渐变的opacity透明度变化实现渐变过渡效果。
下图为hover之后的效果:
相关代码如下:
.box { max-width: 400px; height: 200px; background: linear-gradient(to right, olive, green); position: relative; z-index: 0; }.box::before { content: \; position: absolute; left: 0; top: 0; right: 0; bottom: 0; background: linear-gradient(to right, green, purple); opacity: 0; transition: opacity .5s; z-index: -1;}.box:hover::before { opacity: 1; }