CSS画三角形以及before,after伪元素的应用。

利用css的border属性,即可实现三角形的绘制。

1,代码及效果如下

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<style>
.t0{
  margin:30px;
  height:200px;
  width:200px;
  border-top:solid 100px red;
  border-left:solid 100px green;
  border-right:solid 100px orange;
  border-bottom:solid 100px blue;
}
.t1{
  margin:30px;
  height:0px;
  width:0px;
  border-top:solid 100px red;
  border-left:solid 100px green;
  border-right:solid 100px orange;
  border-bottom:solid 100px blue;

}
.t2{
  margin:30px;
  height:0px;
  width:0px;
  border-top:solid 100px red;
  border-left:solid 100px green;
}
.t3{
  margin:30px;
  height:0px;
  width:0px;
  border-right:solid 100px orange;
  border-bottom:solid 100px transparent;
}
.t4{
  margin:30px;
  height:0px;
  width:0px;
  border-top:solid 100px red;
  border-left:solid 100px transparent;
  border-right:solid 100px transparent;
}
</style>
<body>
<div class="t0"></div>
<div class="t1"></div>
<div class="t2"></div>
<div class="t3"></div>
<div class="t4"></div>
</body>
</html>

 

2,利用before,after伪元素以及三角形绘制实现下列图形

<style>

#demo{
  width:100px;
  height:100px;
  border:2px solid #000;
  position:relative;
}

/* 白色小三角形叠加在黑色大三角形上面,就只剩下2px的黑边了,实现了右边的小凸起效果 */
#demo:before{ content:""; width:0; height:0; position:absolute; left:100px; top:18px; border-top:solid 12px transparent; border-left:solid 12px black; /* 黑色大三角形 */ border-bottom:solid 12px transparent; } #demo:after{ content:""; width:0; height:0; position:absolute; left:100px; top:20px; border-top:solid 10px transparent; border-left:solid 10px white; /* 白色小三角形 */ border-bottom:solid 10px transparent; } </style> <div id="demo"></div>

 

转载于:https://www.cnblogs.com/lanxiansheng/p/7080106.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用CSS伪元素来绘制倒三角形,可以按照以下步骤进行操作: 1. 创建一个具有伪元素的元素。可以使用`::before`或`::after`伪元素来实现。 2. 使用`content: ''`属性来为伪元素创建内容。 3. 设置伪元素的位置属性,例如`position: absolute`,以便将其定位在正确的位置。 4. 使用`width: 0`和`height: 0`属性将伪元素的宽度和高度设置为0,这样它将不会显示任何内容。 5. 使用边框属性设置三角形的样式,例如`border-top`、`border-left`和`border-right`。 6. 根据需要设置边框的颜色和大小。 以下是一个示例代码,演示如何使用CSS伪元素绘制倒三角形: ```css .element::before { content: ''; position: absolute; bottom: -12px; /* 根据需要调整位置 */ left: 50%; /* 根据需要调整位置 */ width: 0; height: 0; border-top: 12px solid #092c53; /* 设置三角形的颜色 */ border-left: 6px solid transparent; /* 可根据需要调整大小 */ border-right: 6px solid transparent; /* 可根据需要调整大小 */ } ``` 请注意,上述代码中的`.element`是一个示例选择器,您可以根据实际情况将其替换为您要应用样式的元素的选择器。另外,您可以根据需要调整位置、大小和颜色的值来实现所需的倒三角形效果。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [css设置利用伪元素设置三角形](https://blog.csdn.net/weixin_52984349/article/details/125857702)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [css伪元素模拟一个三角](https://blog.csdn.net/anny_mei/article/details/119944904)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值