Skip to content

css 绘制三角形

在前端开发时,这样的的需求经常有。绘制三角形:

2023-10-25-17-11-22

不可能总是等着 UI 切图的。前端有办法快速绘制的。

目前的实践方案

参考资料

代码

scss
.item {
	padding-left: 16px;

	position: relative;

	display: flex;
	flex-direction: column;
	justify-content: space-evenly;
	align-items: flex-start;

	width: 123px;
	height: 64px;
	background-color: #08233e;

	&::before {
		content: "";

		$size: 10px;

		height: $size;
		width: $size;

		position: absolute;
		right: 0;
		bottom: 0;

		background-color: #00ffff;
		clip-path: polygon(100% 0, 0 100%, 100% 100%);
	}

	.number-box {
		color: #00ffff;
	}

	.text-box {
		color: #ffffff;
	}
}

实现思路

  1. 伪元素绝对定位,到指定的位置。
  2. clip-path: polygon 实现多边形切割。切割出三角形。
  3. 去专用的网站,可视化绘图,生成路径。

贡献者

The avatar of contributor named as ruan-cat ruan-cat
The avatar of contributor named as 阮喵喵 阮喵喵

页面历史