这次给大家带来css绘制扇形图案,css绘制扇形图案的注意事项有哪些,下面就是实战案例,一起来看一下。
阅读此文需具备基本数学知识:圆心角、弧度制、三角函数。
为实现如下效果呕心沥血:
当然你可以拥抱 svg...在此分享如何纯 css 打造圆环进度条,只需三步!
此物乃 2 + 1 夹心饼干,蓝绿色部分为果酱。显而易见饼干为两个削成了圆形的 p,我们重点演示果酱是怎么制作的:
如图所示,大扇形由 6 个小扇形构成,每一小扇形占整个圆饼的 1/15,大扇形占整个圆饼的 6/15。我们只需构造一个扇形单元,将其复制 6 份后旋转相应角度连接至一起即可。
如何构造扇形?用三角形伪装...
三角形的宽高如何计算?假定圆半径 $radius 为 100px,等分数 $count 为 15。则小扇形的圆心角为 360deg / 15,三角形的高为 100px,宽为 2 * 100px * tan(360deg / 15 / 2)。其中 360deg / 15 / 2 转化弧度制为 pi / 15(pi == 360deg / 2)。
span {
width: 0;
height: 0;
border: $radius solid transparent;
$borderwidth: tan(pi() / $count) * $radius;
border-left-width: $borderwidth;
border-right-width: $borderwidth;
}
数学欠佳的同学请自行科普...
对于 $count 为 1 或 2 的情况需特殊处理,因为 tan(pi) 及 tan(pi / 2) 为无穷值,不了解的同学请研究正切函数图像:
相关代码(其中 $diameter = 2 * $radius 为圆直径):
span {
@if $count == 1 {
width: $diameter;
height: $diameter;
} @else if $count == 2 {
width: $diameter;
height: $radius;
} @else {
width: 0;
height: 0;
border: $radius solid transparent;
$borderwidth: tan(pi() / $count) * $radius;
border-left-width: $borderwidth;
border-right-width: $borderwidth;
}
}
最后,复制并逐一旋转扇形单元:
@for $index from 0 to $count {
span:nth-child(#{$index + 1}) {
$transform: translate(-50%, 0) rotate(360deg / $count / 2 + 360deg * $index / $count);
$origin: if($count == 2, bottom, center);
-webkit-transform: $transform;
transform: $transform;
-webkit-transform-origin: $origin;
transform-origin: $origin;
}
}
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
css3的linear-gradient线性渐变使用方法
css中hover做遮盖罩闪动问题
以上就是css绘制扇形图案的详细内容。