纯HTML5+CSS3制作生日蛋糕(代码易懂)

2020-04-24 18:52:12易采站长站整理

废话不多说,先给大家展示下效果图:

蛋糕分为三个部分,底部蛋糕,顶层蛋糕和蜡烛部分。HTML的布局结构也是按照这三部分布局的。另外就是使用CSS定位和CSS3的rotate,内外阴影等效果调整部分DOM元素样式。比较简单,相信码农都懂的。

不赘述其它有的没的了。

下面给出完整的的HTML代码和CSS代码

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
.birthday .container{
width:600px;
height:600px;
margin:0px auto;
background: #fafafa;
border-radius:5px;
position: relative;
}
/**
** 顶层的
**/
.birthday .top-one{
position: absolute;
width:280px;
height: 280px;
bottom: 200px;
left:160px;
}
.birthday .top-one .bottom{
position: absolute;
width:280px;
height: 280px;
bottom:-30px;
border:1px solid #3e2001;
border-radius: 140px;
transform: rotateX(60deg);
z-index: 4;
background: #3e2001;
box-shadow: 0px 0px 20px #3e2001;
}
.birthday .top-one .top{
position: absolute;
width:280px;
height: 280px;
top:-50px;
border-radius: 140px;
background: #FFFFFF;
transform: rotateX(60deg);
box-shadow: 2px 2px 20px #b7b7b7;
z-index: 6;
background: -webkit-repeating-radial-gradient(circle, #783d01, #3e2001 10px, #914909 10px,white 20px);
background: -moz-repeating-radial-gradient(circle, #783d01, #3e2001 10px,#914909 10px,white 20px);
}
.birthday .top-one .side{
position: absolute;
top:95px;
width:280px;
height: 70px;
border:1px solid #3e2001;
border-top-width: 0px;
border-bottom-width: 0px;
background: #FFFFFF;
z-index: 5;
background: #3e2001;
}
/**
** 底层的
**/
.birthday .bottom-one{
position: absolute;
width:400px;
height: 400px;
bottom: 0px;
left:100px;
}
.birthday .bottom-one .bottom{
position: absolute;
width:400px;
height: 400px;
bottom:-30px;
border:1px solid #914909;
border-radius: 200px;
transform: rotateX(60deg);
box-shadow: 2px 2px 20px #914909;
z-index: 1;
background: #3e2001;
overflow: hidden;
}
.birthday .bottom-one .line{
position: absolute;
width:400px;
height: 400px;
border-radius: 200px;
z-index: 1;
}
.birthday .bottom-one .line1{
bottom: 30px;
border:5px solid #783d01;
left:-5px;
z-index: 1;
}
.birthday .bottom-one .top{
position: absolute;
width:400px;
height: 400px;
top:-100px;
border:1px solid #3e2001;
border-radius: 200px;