这篇文章给大家分享的是有关使用CSS实现渐变色动画边框效果的方法的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。
创新互联是一家集网站建设,林口企业网站建设,林口品牌网站建设,网站定制,林口网站建设报价,网络营销,网络优化,林口网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

https://github.com/comehope/front-end-daily-challenges/tree/master/016-colorful-gradient-animated-border
定义 dom,一个容器中包含一些文字:
you are my
FAVORITE
居中显示:
html,
body,
.box {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}设置页面背景色:
body {
background: #222;
}设置容器和文字样式:
.box {
color: white;
font-size: 2.5em;
width: 10em;
height: 5em;
background: #111;
font-family: sans-serif;
line-height: 1.5em;
text-align: center;
border-radius: 0.2em;
}用伪元素增加一个背板:
.box {
position: relative;
}
.box::after {
content: '';
position: absolute;
width: 102%;
height: 104%;
background-color: orange;
z-index: -1;
border-radius: 0.2em;
}把背板设置为渐变色的:
.box::after {
/*background-color: orange;*/
background-image: linear-gradient(60deg, aquamarine, cornflowerblue, goldenrod, hotpink, salmon, lightgreen, sandybrown, violet);
}为背板设置动画效果:
.box::after {
background-size: 300%, 300%;
animation: animate_bg 5s ease infinite alternate;
}
@keyframes animate_bg {
0% {
background-position: 0%, 50%;
}
50% {
background-position: 100%, 50%;
}
100% {
background-position: 0%, 50%;
}
}最后,再为文字增加变色效果:
.box {
animation: animate_text 2s linear infinite alternate;
}
@keyframes animate_text {
from {
color: lime;
}
to {
color: yellow;
}
}大功告成!
感谢各位的阅读!关于使用CSS实现渐变色动画边框效果的方法就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到吧!