CSS三角形和圣诞树

1.三角形的本质是盒子长宽都是0,边框X切成四个区域,哪个区域显示,就把那个区域的颜色设置一下。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box {
            /* 1.将盒子的宽和高都设为0 */
            width: 0;
            height: 0;
            /* 2.设置边框宽度,这里的100px是盒子中心的尖尖到边的距离。并将所有边框的颜色都透明 */
            border: 100px solid transparent;
            /* 3.需要哪个三角形就设置哪边的颜色 */
            border-bottom-color: green;
        }

        
    </style>
</head>
<body>
    <div id="box"></div>
</body>
</html>

在这里插入图片描述

2.圣诞树
FED76

<!DOCTYPE html>
<html>
    <head>
        <meta charset=utf-8>
        <style type="text/css">
            .topbranch {
                width: 0px;
                height: 0px;
                /*
                * TODO: 上枝叶效果
                */
                border: solid 100px transparent;
                border-bottom-color: green;
                float:left;
                margin-left: 100px; 
                
            }
            .middleBranch {
                width: 0px;
                height: 0px;
                /*
                * TODO: 中枝叶效果
                */
                border: solid 200px transparent;
                border-bottom-color: green;
        
                
            }
            .base {
                /*
                * TODO: 树干效果
                */
                width: 70px;
                height: 200px;
                background-color: gray;
                margin-left: 165px;
            }
        </style>
    </head>
    <body>
    	<section class="topbranch"></section>
        <section class="middleBranch"></section>
        <section class="base"></section>
    </body>
</html>

这里最上面的盒子设置浮动可以脱标,让下面的三角形挤上来,正好看上去连起来了。
盒子2的边框宽是100px,正方形是200200.
盒子2的边框宽是200px,正方形是400
400。
所以看上去正好卡在一起。
在这里插入图片描述
树干就很简单,先右移动200px,再回去半个树干,所以是200-35=165.

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值