您现在的位置是:网站首页>列表内容
使用纯 CSS 创作一个渐变色动画边框_CSS教程_CSS_网页制作_
2021-09-10 20:46:01 707人已围观
简介 这篇文章主要介绍了使用纯 CSS 创作一个渐变色动画边框,需要的朋友可以参考下
效果预览
按下右侧的“点击预览”按钮可以在当前页面预览,点击链接可以全屏预览。
https://codepen.io/comehope/pen/odpRKX
可交互视频教程
此视频是可以交互的,你可以随时暂停视频,编辑视频中的代码。
请用 chrome, safari, edge 打开观看。
源代码下载
请从 github 下载。
代码解读
定义 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; } }
大功告成!
知识点
•z-index https://developer.mozilla.org/en-US/docs/Web/CSS/z-index
•background-image https://developer.mozilla.org/en-US/docs/Web/CSS/background-image
•background-size https://developer.mozilla.org/en-US/docs/Web/CSS/background-size
•background-position https://developer.mozilla.org/en-US/docs/Web/CSS/background-position
总结
以上所述是小编给大家介绍的使用纯 CSS 创作一个渐变色动画边框,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
点击排行
- 刀塔传奇远征不死一次通关秘籍_手机游戏_游戏攻略_
- 崩坏学园2成就系统详解 赢称号免费获得水晶介绍_手机游戏_游戏攻略_
- 崩坏学园2乱入的胖次活动攻略 巨盾娘打法详解_手机游戏_游戏攻略_
- 天天飞车购买赛车车手返钻活动 升级充值均可获得返利介绍_手机游戏_游戏攻略_
- 梅露可物语麻痹宠怎么选_梅露可物语麻痹宠选择技巧_手机游戏_游戏攻略_
- 梅露可物语 魔宠攻击顺序不同伤害也不同_影响总攻击力介绍_手机游戏_游戏攻略_
- 全民精灵修改攻击力方法_手机游戏_游戏攻略_
- 梅露可物语阵容搭配 辨别伙伴成长潜力技巧_手机游戏_游戏攻略_
- 天天富翁第一名骰子值得购买 第一名骰子属性详细介绍_手机游戏_游戏攻略_
本栏推荐
-
刀塔传奇远征不死一次通关秘籍_手机游戏_游戏攻略_
-
崩坏学园2成就系统详解 赢称号免费获得水晶介绍_手机游戏_游戏攻略_
-
崩坏学园2乱入的胖次活动攻略 巨盾娘打法详解_手机游戏_游戏攻略_
-
天天飞车购买赛车车手返钻活动 升级充值均可获得返利介绍_手机游戏_游戏攻略_
-
梅露可物语麻痹宠怎么选_梅露可物语麻痹宠选择技巧_手机游戏_游戏攻略_
-
梅露可物语 魔宠攻击顺序不同伤害也不同_影响总攻击力介绍_手机游戏_游戏攻略_
-
全民精灵修改攻击力方法_手机游戏_游戏攻略_
-
梅露可物语阵容搭配 辨别伙伴成长潜力技巧_手机游戏_游戏攻略_
-
天天富翁第一名骰子值得购买 第一名骰子属性详细介绍_手机游戏_游戏攻略_