html如何制作圣诞树,怎么用css画圣诞树?

html与css学习过程中会遇到各种各样的问题,当然也有很多有趣的实战应用,今天与大家分享如何用css来控制div画三角形,进一步画出圣诞树。

5e15a6c7ecbe8366.jpg

画圣诞树,我们首先需要会用css画三角形,(相关推荐:如何用css3画三角形)。

学会了画三角形,我们就可以开始画圣诞树了。

用css画圣诞树的步骤:

(1)画两个三角形,先画出两个大小不同三角形。#tri1{

width: 0px;

height: 0px;

border-top: 100px solid white;

border-right: 100px solid white;

border-bottom: 100px solid green;

border-left: 100px solid white;

}

#tri2{

width: 0px;

height: 0px;

border-top: 200px solid white;

border-right: 200px solid white;

border-bottom: 200px solid green;

border-left: 200px solid white;

}

1578477074288875.png

(2)利用浮动以及margin调到合适位置

将第一个小三角形浮动起来,这样就覆盖到第2个上面,然后利用margin值调动位置,最终显示出圣诞树的上面内容,代码如下#tri1{

width: 0px;

height: 0px;

border-top: 100px solid white;

border-right: 100px solid white;

border-bottom: 100px solid green;

border-left: 100px solid white;

float: left;

margin-left: 100px;

}

#tri2{

width: 0px;

height: 0px;

border-top: 200px solid white;

border-right: 200px solid white;

border-bottom: 200px solid green;

border-left: 200px solid white;

}

(3)、画树干

再加入一个div名字为footer,控制其大小形状与颜色,并用margin调整期位置。#footer{

width: 100px;

height: 200px;

background: gray;

margin-left: 150px;

}

最终,经过调整得到一课圣诞树。如下图所示(推荐学习:CSS视频教程)

1578477151797779.png

所有代码如下:

圣诞树练习

#header{

width: 0px;

height: 0px;

border-top: 100px solid white;

border-right: 100px solid white;

border-bottom: 100px solid green;

border-left: 100px solid white;

float: left;

margin-left: 100px;

}

#main{

width: 0px;

height: 0px;

border-top: 200px solid white;

border-right: 200px solid white;

border-bottom: 200px solid green;

border-left: 200px solid white;

}

#footer{

width: 100px;

height: 200px;

background: gray;

margin-left: 150px;

}

更多CSS3相关技术文章,请访问CSS3答疑栏目进行学习!

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值