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圣诞树与雪的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!


原文地址:https://blog.csdn.net/cuken7684698822/article/details/107842924
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.chinasem.cn/article/775147

相关文章

全面解析HTML5中Checkbox标签

《全面解析HTML5中Checkbox标签》Checkbox是HTML5中非常重要的表单元素之一,通过合理使用其属性和样式自定义方法,可以为用户提供丰富多样的交互体验,这篇文章给大家介绍HTML5中C... 在html5中,Checkbox(复选框)是一种常用的表单元素,允许用户在一组选项中选择多个项目。本

HTML5 搜索框Search Box详解

《HTML5搜索框SearchBox详解》HTML5的搜索框是一个强大的工具,能够有效提升用户体验,通过结合自动补全功能和适当的样式,可以创建出既美观又实用的搜索界面,这篇文章给大家介绍HTML5... html5 搜索框(Search Box)详解搜索框是一个用于输入查询内容的控件,通常用于网站或应用程

CSS3中的字体及相关属性详解

《CSS3中的字体及相关属性详解》:本文主要介绍了CSS3中的字体及相关属性,详细内容请阅读本文,希望能对你有所帮助... 字体网页字体的三个来源:用户机器上安装的字体,放心使用。保存在第三方网站上的字体,例如Typekit和Google,可以link标签链接到你的页面上。保存在你自己Web服务器上的字

html 滚动条滚动过快会留下边框线的解决方案

《html滚动条滚动过快会留下边框线的解决方案》:本文主要介绍了html滚动条滚动过快会留下边框线的解决方案,解决方法很简单,详细内容请阅读本文,希望能对你有所帮助... 滚动条滚动过快时,会留下边框线但其实大部分时候是这样的,没有多出边框线的滚动条滚动过快时留下边框线的问题通常与滚动条样式和滚动行

使用vscode搭建pywebview集成vue项目实践

《使用vscode搭建pywebview集成vue项目实践》:本文主要介绍使用vscode搭建pywebview集成vue项目实践,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录环境准备项目源码下载项目说明调试与生成可执行文件核心代码说明总结本节我们使用pythonpywebv

使用Python和Tkinter实现html标签去除工具

《使用Python和Tkinter实现html标签去除工具》本文介绍用Python和Tkinter开发的HTML标签去除工具,支持去除HTML标签、转义实体并输出纯文本,提供图形界面操作及复制功能,需... 目录html 标签去除工具功能介绍创作过程1. 技术选型2. 核心实现逻辑3. 用户体验增强如何运行

CSS 样式表的四种应用方式及css注释的应用小结

《CSS样式表的四种应用方式及css注释的应用小结》:本文主要介绍了CSS样式表的四种应用方式及css注释的应用小结,本文通过实例代码给大家介绍的非常详细,详细内容请阅读本文,希望能对你有所帮助... 一、外部 css(推荐方式)定义:将 CSS 代码保存为独立的 .css 文件,通过 <link> 标签

使用Vue-ECharts实现数据可视化图表功能

《使用Vue-ECharts实现数据可视化图表功能》在前端开发中,经常会遇到需要展示数据可视化的需求,比如柱状图、折线图、饼图等,这类需求不仅要求我们准确地将数据呈现出来,还需要兼顾美观与交互体验,所... 目录前言为什么选择 vue-ECharts?1. 基于 ECharts,功能强大2. 更符合 Vue

Vue中插槽slot的使用示例详解

《Vue中插槽slot的使用示例详解》:本文主要介绍Vue中插槽slot的使用示例详解,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录一、插槽是什么二、插槽分类2.1 匿名插槽2.2 具名插槽2.3 作用域插槽三、插槽的基本使用3.1 匿名插槽

springboot+vue项目怎么解决跨域问题详解

《springboot+vue项目怎么解决跨域问题详解》:本文主要介绍springboot+vue项目怎么解决跨域问题的相关资料,包括前端代理、后端全局配置CORS、注解配置和Nginx反向代理,... 目录1. 前端代理(开发环境推荐)2. 后端全局配置 CORS(生产环境推荐)3. 后端注解配置(按接口