CSS3圣诞树与雪

2024-03-05 03:10
文章标签 frontend css3 圣诞树

本文主要是介绍CSS3圣诞树与雪,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

CSS3 Christmas Tree with Snow
CSS3 Christmas Tree with Snow

CSS3 Christmas Tree with Snow Today we will continue use CSS3 in drawing complex shapes. We will create very nice CSS3 Christmas Tree demonstration. We will be drawing the tree, six colored balls on it, three snow hills and snowfall.

CSS3圣诞树雪今天,我们将继续在绘制复杂的形状,使用CSS3。 我们将创建非常漂亮CSS3圣诞树演示。 我们将绘制树,树上六个彩色的球,三个雪山和降雪。

Here are our final result:

这是我们的最终结果:

CSS3 Christmas Tree

CSS3 Christmas Tree
现场演示
下载结果

Ok, download the example files and lets start coding !

好的,下载示例文件并开始编码!

步骤1. HTML (Step 1. HTML)

First, let us create the HTML markup. As you can see – the structure is quite minimal and contains only several DIV elements.

首先,让我们创建HTML标记。 如您所见–结构非常小,仅包含几个DIV元素。

index.html (index.html)

<!DOCTYPE html>
<html lang="en" ><head><meta charset="utf-8" /><title>CSS3 Christmas Tree with Snow | Script Tutorials</title><link href="css/layout.css" rel="stylesheet" type="text/css" /></head><body><header><h2>CSS3 Christmas Tree with Snow</h2><a href="https://www.script-tutorials.com/css3-christmas-tree-with-snow/" class="stuts">Back to original tutorial on <span>Script Tutorials</span></a></header><div class="container"><div class="bottom_snow"></div><div class="tree"></div><div class="tree_bot"></div><div class="ball red"></div><div class="ball green"></div><div class="ball blue"></div><div class="ball red rsmall"></div><div class="ball green gsmall"></div><div class="ball blue bsmall"></div><h1>Happy Holidays</h1><div class="fall_snow"></div></div></body>
</html>

<!DOCTYPE html>
<html lang="en" ><head><meta charset="utf-8" /><title>CSS3 Christmas Tree with Snow | Script Tutorials</title><link href="css/layout.css" rel="stylesheet" type="text/css" /></head><body><header><h2>CSS3 Christmas Tree with Snow</h2><a href="https://www.script-tutorials.com/css3-christmas-tree-with-snow/" class="stuts">Back to original tutorial on <span>Script Tutorials</span></a></header><div class="container"><div class="bottom_snow"></div><div class="tree"></div><div class="tree_bot"></div><div class="ball red"></div><div class="ball green"></div><div class="ball blue"></div><div class="ball red rsmall"></div><div class="ball green gsmall"></div><div class="ball blue bsmall"></div><h1>Happy Holidays</h1><div class="fall_snow"></div></div></body>
</html>

步骤2. CSS (Step 2. CSS)

Now, there are the CSS rules that will turn our boring DIVs into a magical set of Christmas card elements. I have already commented the CSS below, so you can see the major parts of this file.

现在,有一些CSS规则会将无聊的DIV变成一组神奇的圣诞贺卡元素。 我已经在下面评论了CSS,因此您可以看到此文件的主要部分。

css / slideshow.css (css/slideshow.css)

*{margin:0;padding:0;
}
body {background-color:#eee;color:#fff;font:14px/1.3 Arial,sans-serif;
}
header {background-color:#212121;box-shadow: 0 -1px 2px #111111;display:block;height:70px;position:relative;width:100%;z-index:100;
}
header h2{font-size:22px;font-weight:normal;left:50%;margin-left:-400px;padding:22px 0;position:absolute;width:540px;
}
header a.stuts,a.stuts:visited{border:none;text-decoration:none;color:#fcfcfc;font-size:14px;left:50%;line-height:31px;margin:23px 0 0 110px;position:absolute;top:0;
}
header .stuts span {font-size:22px;font-weight:bold;margin-left:5px;
}
/* style the main area */
.container {height: 500px;margin: 50px auto;overflow: hidden;position: relative;width: 800px;background-color: #0093d8;background: -moz-linear-gradient(top, #0093d8, #fff);background: -webkit-gradient(linear,left bottom,left top,color-stop(0, #fff),color-stop(1, #0093d8));-moz-box-shadow: 0 10px 10px rgba(0,0,0,0.5);-webkit-box-shadow: 0 10px 10px rgba(0,0,0,0.5);box-shadow: 0 10px 10px rgba(0,0,0,0.5);
}
/* style the bottom snow */
.bottom_snow {position: absolute;z-index: 5;top: 400px;left: 50%;margin-left: -500px;width: 1000px;height: 1000px;background: #e2e2e2;border-radius: 1000px;-moz-border-radius: 1000px;-webkit-border-radius: 1000px;
}
.bottom_snow:before , .bottom_snow:after {background-color: #fff;content: "";height: 1000px;position: absolute;top: -25px;width: 1000px;border-radius: 1000px;-moz-border-radius: 1000px;-webkit-border-radius: 1000px;
}
.bottom_snow:before {left: 400px;
}
.bottom_snow:after {right: 400px;
}
/* style the label */
h1 {color: #FAFAFA;font: bold 80px 'Comic Sans MS',Arial;text-align: center;text-shadow: 2px 2px 1px rgba(0, 0, 0, 0.85), 4px 4px 0 #CFEAED;text-transform: uppercase;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-o-user-select: none;user-select: none;
}
/* style the tree */
.tree, .tree:before, .tree:after, .tree_bot, .tree_bot:before, .tree_bot:after {height: 0;position: absolute;width: 0;border-radius: 40px;-moz-border-radius: 40px;-webkit-border-radius: 40px;
}
.tree {border-left: 20px solid transparent;border-right: 20px solid transparent;border-bottom: 20px solid green;left: 390px;top: 135px;
}
.tree:before {content:'';border-left: 40px solid transparent;border-right: 40px solid transparent;border-bottom: 40px solid green;left: -40px;top: 15px;
}
.tree:after {content:'';border-left: 60px solid transparent;border-right: 60px solid transparent;border-bottom: 60px solid green;left: -60px;top: 40px;
}
/* tree, bottom side */
.tree_bot {border-left: 80px solid transparent;border-right: 80px solid transparent;border-bottom: 80px solid green;left: 330px;top: 210px;
}
.tree_bot:before {content:'';border-left: 100px solid transparent;border-right: 100px solid transparent;border-bottom: 100px solid green;left: -100px;top: 40px;
}
.tree_bot:after {content:'';border-left: 120px solid transparent;border-right: 120px solid transparent;border-bottom: 120px solid green;left: -120px;top: 80px;
}
/* style the balls */
.ball {height: 40px;left: 390px;position: absolute;top: 345px;width: 40px;border-radius: 40px;-moz-border-radius: 40px;-webkit-border-radius: 40px;box-shadow: 0 0 5px #777;-moz-box-shadow: 0 0 5px #777;-webkit-box-shadow: 0 0 5px #777;
}
.red {background-color: #c8171f;background-image: -webkit-radial-gradient(50% 50%, circle, #f9d0be, #c8171f 70%);background-image: -moz-radial-gradient(50% 50%, circle, #f9d0be, #c8171f 70%);background-image: -o-radial-gradient(50% 50%, circle, #f9d0be, #c8171f 70%);background-image: radial-gradient(50% 50%, circle, #f9d0be, #c8171f 70%);left: 340px;top: 325px;
}
.blue {background-color: #00a1ee;background-image: -webkit-radial-gradient(50% 50%, circle, #cde6f9, #00a1ee 70%);background-image: -moz-radial-gradient(50% 50%, circle, #cde6f9, #00a1ee 70%);background-image: -o-radial-gradient(50% 50%, circle, #cde6f9, #00a1ee 70%);background-image: radial-gradient(50% 50%, circle, #cde6f9, #00a1ee 70%);
}
.green {background-color: #4d8d00;background-image: -webkit-radial-gradient(50% 50%, circle, #d1e5b2, #4d8d00 70%);background-image: -moz-radial-gradient(50% 50%, circle, #d1e5b2, #4d8d00 70%);background-image: -o-radial-gradient(50% 50%, circle, #d1e5b2, #4d8d00 70%);background-image: radial-gradient(50% 50%, circle, #d1e5b2, #4d8d00 70%);left: 440px;top: 325px;
}
.rsmall, .gsmall, .bsmall {height: 25px;width: 25px;
}
.rsmall {left: 440px;top: 255px;
}
.bsmall {left: 350px;top: 255px;
}
.gsmall {left: 395px;top: 275px;
}
/* style the falling snow */
.fall_snow {background-image: url('../images/snow1.png'), url('../images/snow2.png'), url('../images/snow3.png');height: 100%;left: 0;position: absolute;top: 0;width: 100%;-webkit-animation: snow 10s linear infinite;-moz-animation: snow 10s linear infinite;-ms-animation: snow 10s linear infinite;animation: snow 10s linear infinite;
}
@keyframes snow {0% {background-position: 0px 0px, 0px 0px, 0px 0px;}50% {background-position: 500px 500px, 100px 200px, -100px 150px;}100% {background-position: 500px 1000px, 200px 400px, -100px 300px;}
}
@-moz-keyframes snow {0% {background-position: 0px 0px, 0px 0px, 0px 0px;}50% {background-position: 500px 500px, 100px 200px, -100px 150px;}100% {background-position: 400px 1000px, 200px 400px, 100px 300px;}
}
@-webkit-keyframes snow {0% {background-position: 0px 0px, 0px 0px, 0px 0px;}50% {background-position: 500px 500px, 100px 200px, -100px 150px;}100% {background-position: 500px 1000px, 200px 400px, -100px 300px;}
}
@-ms-keyframes snow {0% {background-position: 0px 0px, 0px 0px, 0px 0px;}50% {background-position: 500px 500px, 100px 200px, -100px 150px;}100% {background-position: 500px 1000px, 200px 400px, -100px 300px;}
}

*{margin:0;padding:0;
}
body {background-color:#eee;color:#fff;font:14px/1.3 Arial,sans-serif;
}
header {background-color:#212121;box-shadow: 0 -1px 2px #111111;display:block;height:70px;position:relative;width:100%;z-index:100;
}
header h2{font-size:22px;font-weight:normal;left:50%;margin-left:-400px;padding:22px 0;position:absolute;width:540px;
}
header a.stuts,a.stuts:visited{border:none;text-decoration:none;color:#fcfcfc;font-size:14px;left:50%;line-height:31px;margin:23px 0 0 110px;position:absolute;top:0;
}
header .stuts span {font-size:22px;font-weight:bold;margin-left:5px;
}
/* style the main area */
.container {height: 500px;margin: 50px auto;overflow: hidden;position: relative;width: 800px;background-color: #0093d8;background: -moz-linear-gradient(top, #0093d8, #fff);background: -webkit-gradient(linear,left bottom,left top,color-stop(0, #fff),color-stop(1, #0093d8));-moz-box-shadow: 0 10px 10px rgba(0,0,0,0.5);-webkit-box-shadow: 0 10px 10px rgba(0,0,0,0.5);box-shadow: 0 10px 10px rgba(0,0,0,0.5);
}
/* style the bottom snow */
.bottom_snow {position: absolute;z-index: 5;top: 400px;left: 50%;margin-left: -500px;width: 1000px;height: 1000px;background: #e2e2e2;border-radius: 1000px;-moz-border-radius: 1000px;-webkit-border-radius: 1000px;
}
.bottom_snow:before , .bottom_snow:after {background-color: #fff;content: "";height: 1000px;position: absolute;top: -25px;width: 1000px;border-radius: 1000px;-moz-border-radius: 1000px;-webkit-border-radius: 1000px;
}
.bottom_snow:before {left: 400px;
}
.bottom_snow:after {right: 400px;
}
/* style the label */
h1 {color: #FAFAFA;font: bold 80px 'Comic Sans MS',Arial;text-align: center;text-shadow: 2px 2px 1px rgba(0, 0, 0, 0.85), 4px 4px 0 #CFEAED;text-transform: uppercase;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-o-user-select: none;user-select: none;
}
/* style the tree */
.tree, .tree:before, .tree:after, .tree_bot, .tree_bot:before, .tree_bot:after {height: 0;position: absolute;width: 0;border-radius: 40px;-moz-border-radius: 40px;-webkit-border-radius: 40px;
}
.tree {border-left: 20px solid transparent;border-right: 20px solid transparent;border-bottom: 20px solid green;left: 390px;top: 135px;
}
.tree:before {content:'';border-left: 40px solid transparent;border-right: 40px solid transparent;border-bottom: 40px solid green;left: -40px;top: 15px;
}
.tree:after {content:'';border-left: 60px solid transparent;border-right: 60px solid transparent;border-bottom: 60px solid green;left: -60px;top: 40px;
}
/* tree, bottom side */
.tree_bot {border-left: 80px solid transparent;border-right: 80px solid transparent;border-bottom: 80px solid green;left: 330px;top: 210px;
}
.tree_bot:before {content:'';border-left: 100px solid transparent;border-right: 100px solid transparent;border-bottom: 100px solid green;left: -100px;top: 40px;
}
.tree_bot:after {content:'';border-left: 120px solid transparent;border-right: 120px solid transparent;border-bottom: 120px solid green;left: -120px;top: 80px;
}
/* style the balls */
.ball {height: 40px;left: 390px;position: absolute;top: 345px;width: 40px;border-radius: 40px;-moz-border-radius: 40px;-webkit-border-radius: 40px;box-shadow: 0 0 5px #777;-moz-box-shadow: 0 0 5px #777;-webkit-box-shadow: 0 0 5px #777;
}
.red {background-color: #c8171f;background-image: -webkit-radial-gradient(50% 50%, circle, #f9d0be, #c8171f 70%);background-image: -moz-radial-gradient(50% 50%, circle, #f9d0be, #c8171f 70%);background-image: -o-radial-gradient(50% 50%, circle, #f9d0be, #c8171f 70%);background-image: radial-gradient(50% 50%, circle, #f9d0be, #c8171f 70%);left: 340px;top: 325px;
}
.blue {background-color: #00a1ee;background-image: -webkit-radial-gradient(50% 50%, circle, #cde6f9, #00a1ee 70%);background-image: -moz-radial-gradient(50% 50%, circle, #cde6f9, #00a1ee 70%);background-image: -o-radial-gradient(50% 50%, circle, #cde6f9, #00a1ee 70%);background-image: radial-gradient(50% 50%, circle, #cde6f9, #00a1ee 70%);
}
.green {background-color: #4d8d00;background-image: -webkit-radial-gradient(50% 50%, circle, #d1e5b2, #4d8d00 70%);background-image: -moz-radial-gradient(50% 50%, circle, #d1e5b2, #4d8d00 70%);background-image: -o-radial-gradient(50% 50%, circle, #d1e5b2, #4d8d00 70%);background-image: radial-gradient(50% 50%, circle, #d1e5b2, #4d8d00 70%);left: 440px;top: 325px;
}
.rsmall, .gsmall, .bsmall {height: 25px;width: 25px;
}
.rsmall {left: 440px;top: 255px;
}
.bsmall {left: 350px;top: 255px;
}
.gsmall {left: 395px;top: 275px;
}
/* style the falling snow */
.fall_snow {background-image: url('../images/snow1.png'), url('../images/snow2.png'), url('../images/snow3.png');height: 100%;left: 0;position: absolute;top: 0;width: 100%;-webkit-animation: snow 10s linear infinite;-moz-animation: snow 10s linear infinite;-ms-animation: snow 10s linear infinite;animation: snow 10s linear infinite;
}
@keyframes snow {0% {background-position: 0px 0px, 0px 0px, 0px 0px;}50% {background-position: 500px 500px, 100px 200px, -100px 150px;}100% {background-position: 500px 1000px, 200px 400px, -100px 300px;}
}
@-moz-keyframes snow {0% {background-position: 0px 0px, 0px 0px, 0px 0px;}50% {background-position: 500px 500px, 100px 200px, -100px 150px;}100% {background-position: 400px 1000px, 200px 400px, 100px 300px;}
}
@-webkit-keyframes snow {0% {background-position: 0px 0px, 0px 0px, 0px 0px;}50% {background-position: 500px 500px, 100px 200px, -100px 150px;}100% {background-position: 500px 1000px, 200px 400px, -100px 300px;}
}
@-ms-keyframes snow {0% {background-position: 0px 0px, 0px 0px, 0px 0px;}50% {background-position: 500px 500px, 100px 200px, -100px 150px;}100% {background-position: 500px 1000px, 200px 400px, -100px 300px;}
}

现场演示
下载结果

结论 (Conclusion)

Today we have made great Christmas tree with snow with using pseudo-elements like :before and :after. Just one little problem – IE browsers. Even if IE8 has support these pseudo-elements, it totally lacks CSS3 support, so our result will looks not so good. I wish you a Merry Christmas and Happy Holidays!

今天,我们使用了:before和:after这样的伪元素,用雪制作了精美的圣诞树。 只是一个小问题-IE浏览器。 即使IE8支持这些伪元素,它也完全缺少CSS3支持,因此我们的结果看起来不太好。 祝您圣诞快乐,节日快乐!

翻译自: https://www.script-tutorials.com/css3-christmas-tree-with-snow/

这篇关于CSS3圣诞树与雪的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/775147

相关文章

React实现原生APP切换效果

《React实现原生APP切换效果》最近需要使用Hybrid的方式开发一个APP,交互和原生APP相似并且需要IM通信,本文给大家介绍了使用React实现原生APP切换效果,文中通过代码示例讲解的非常... 目录背景需求概览技术栈实现步骤根据 react-router-dom 文档配置好路由添加过渡动画使用

如何用Python绘制简易动态圣诞树

《如何用Python绘制简易动态圣诞树》这篇文章主要给大家介绍了关于如何用Python绘制简易动态圣诞树,文中讲解了如何通过编写代码来实现特定的效果,包括代码的编写技巧和效果的展示,需要的朋友可以参考... 目录代码:效果:总结 代码:import randomimport timefrom math

使用Vue.js报错:ReferenceError: “Vue is not defined“ 的原因与解决方案

《使用Vue.js报错:ReferenceError:“Vueisnotdefined“的原因与解决方案》在前端开发中,ReferenceError:Vueisnotdefined是一个常见... 目录一、错误描述二、错误成因分析三、解决方案1. 检查 vue.js 的引入方式2. 验证 npm 安装3.

vue如何监听对象或者数组某个属性的变化详解

《vue如何监听对象或者数组某个属性的变化详解》这篇文章主要给大家介绍了关于vue如何监听对象或者数组某个属性的变化,在Vue.js中可以通过watch监听属性变化并动态修改其他属性的值,watch通... 目录前言用watch监听深度监听使用计算属性watch和计算属性的区别在vue 3中使用watchE

python解析HTML并提取span标签中的文本

《python解析HTML并提取span标签中的文本》在网页开发和数据抓取过程中,我们经常需要从HTML页面中提取信息,尤其是span元素中的文本,span标签是一个行内元素,通常用于包装一小段文本或... 目录一、安装相关依赖二、html 页面结构三、使用 BeautifulSoup javascript

Vue3 的 shallowRef 和 shallowReactive:优化性能

大家对 Vue3 的 ref 和 reactive 都很熟悉,那么对 shallowRef 和 shallowReactive 是否了解呢? 在编程和数据结构中,“shallow”(浅层)通常指对数据结构的最外层进行操作,而不递归地处理其内部或嵌套的数据。这种处理方式关注的是数据结构的第一层属性或元素,而忽略更深层次的嵌套内容。 1. 浅层与深层的对比 1.1 浅层(Shallow) 定义

这15个Vue指令,让你的项目开发爽到爆

1. V-Hotkey 仓库地址: github.com/Dafrok/v-ho… Demo: 戳这里 https://dafrok.github.io/v-hotkey 安装: npm install --save v-hotkey 这个指令可以给组件绑定一个或多个快捷键。你想要通过按下 Escape 键后隐藏某个组件,按住 Control 和回车键再显示它吗?小菜一碟: <template

【 html+css 绚丽Loading 】000046 三才归元阵

前言:哈喽,大家好,今天给大家分享html+css 绚丽Loading!并提供具体代码帮助大家深入理解,彻底掌握!创作不易,如果能帮助到大家或者给大家一些灵感和启发,欢迎收藏+关注哦 💕 目录 📚一、效果📚二、信息💡1.简介:💡2.外观描述:💡3.使用方式:💡4.战斗方式:💡5.提升:💡6.传说: 📚三、源代码,上代码,可以直接复制使用🎥效果🗂️目录✍️

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

计算机毕业设计 大学志愿填报系统 Java+SpringBoot+Vue 前后端分离 文档报告 代码讲解 安装调试

🍊作者:计算机编程-吉哥 🍊简介:专业从事JavaWeb程序开发,微信小程序开发,定制化项目、 源码、代码讲解、文档撰写、ppt制作。做自己喜欢的事,生活就是快乐的。 🍊心愿:点赞 👍 收藏 ⭐评论 📝 🍅 文末获取源码联系 👇🏻 精彩专栏推荐订阅 👇🏻 不然下次找不到哟~Java毕业设计项目~热门选题推荐《1000套》 目录 1.技术选型 2.开发工具 3.功能