本篇文章给大家带来的内容是关于如何使用纯css实现锡纸撕开的文字效果(附代码) ,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
效果预览
源代码下载
https://github.com/comehope/front-end-daily-challenges
代码解读
定义 dom,容器中包含若干子元素,每个子元素中包含一个字母:
A W E S O M E
登录后复制
定义容器尺寸:
立即学习“前端免费学习笔记(深入)”;
- body { margin: 0; height: 100vh;}.text { width: 100%; height: 100%;}
登录后复制
设置子元素的布局方式:
- .text { display: flex; justify-content: space-between;}.text span { width: 100%;}
登录后复制
定义文本样式:
- .text span { color: darkslategray; background-color: rgb(127, 140, 141); font-family: serif; font-size: 12vmin; text-shadow: 1px 1px 1px white; display: flex; align-items: center; justify-content: center;}
登录后复制
设置文本的背景的渐变色,奇数位的文字和偶数位的文字的渐变方向是相反的:
- .text span:nth-child(odd) { background: linear-gradient( to bottom, rgba(127, 140, 141, 0.2) 0%, rgba(127, 140, 141, 0) 33%, rgba(127, 140, 141, 0.7) 66%, rgba(127, 140, 141, 0.2) 100% );}.text span:nth-child(even) { background: linear-gradient( to top, rgba(127, 140, 141, 0.2) 0%, rgba(127, 140, 141, 0) 33%, rgba(127, 140, 141, 0.7) 66%, rgba(127, 140, 141, 0.2) 100% );}
登录后复制
增加文字之间的分隔线,第1个文字之前不用加分隔线:
- .text span { position: relative;}.text span:not(:first-child)::before { content: ''; position: absolute; width: 10px; height: 90%; background-color: black; left: -5px; border-left: 1px solid white; border-radius: 50%;}
登录后复制
让分隔线上下错位:
- .text span:not(:first-child):nth-child(odd)::before { top: 2%;}.text span:not(:first-child):nth-child(even)::before { bottom: 2%;}
登录后复制
大功告成!
相关推荐:
如何用纯CSS实现接扎啤的特效(附源码)
如何用纯CSS实现接扎啤的特效(附源码)
如何用纯CSS实现接扎啤的特效(附源码)
以上就是如何使用纯CSS实现锡纸撕开的文字效果(附代码)的详细内容,更多请关注【创想鸟】其它相关文章!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。