欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 美景 > 绘制三角形、正六边形、五角星、六角星

绘制三角形、正六边形、五角星、六角星

2025/9/18 16:48:20 来源:https://blog.csdn.net/lulei5153/article/details/144721925  浏览:    关键词:绘制三角形、正六边形、五角星、六角星

<!DOCTYPE html>
<html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>绘制图形</title><style>body {display: flex;justify-content: center;align-items: center;height: 100vh;margin: 0;}/* 三角形 */.single-triangle {width: 0;height: 0;border-left: 50px solid transparent;/* 调整长度可以改变三角形的宽度 */border-right: 50px solid transparent;/* 调整长度可以改变三角形的宽度 */border-bottom: 100px solid blue;/* 调整长度可以改变三角形的高度 */margin-right: 120px;/* 在三角形右侧添加间距 */}/* 正六边形 */.hexagon-container {position: relative;width: 100px;height: 100px;}.hexagon-triangle {width: 0;height: 0;border-left: 50px solid transparent;border-right: 50px solid transparent;border-bottom: 86.6px solid blue;/* 50 * sqrt(3) */position: absolute;bottom: 0;transform-origin: 0 100%;}.hexagon-triangle:nth-child(1) {transform: rotate(0deg);border-bottom-color: red;}.hexagon-triangle:nth-child(2) {transform: rotate(60deg);border-bottom-color: orange;}.hexagon-triangle:nth-child(3) {transform: rotate(120deg);border-bottom-color: yellow;}.hexagon-triangle:nth-child(4) {transform: rotate(180deg);border-bottom-color: green;}.hexagon-triangle:nth-child(5) {transform: rotate(240deg);border-bottom-color: blue;}.hexagon-triangle:nth-child(6) {transform: rotate(300deg);border-bottom-color: purple;}h2 {margin-right: 100px;}/* 六角星 */.shape-holder {position: relative;width: 100px;height: 57.7px;/* 100 * sqrt(3) / 2 */margin-left: 30px;}.triangle-part {width: 0;height: 0;border-left: 50px solid transparent;border-right: 50px solid transparent;border-bottom: 93.3px solid blue;/* 100 * sqrt(3) */position: absolute;bottom: 0;transform-origin: 50% 100%;}.triangle-part:nth-child(1) {transform: rotate(0deg);/* border-bottom-color: red; */}.triangle-part:nth-child(2) {transform: rotate(60deg);/* border-bottom-color: orange; */}.triangle-part:nth-child(3) {transform: rotate(120deg);/* border-bottom-color: yellow; */}.triangle-part:nth-child(4) {transform: rotate(180deg);/* border-bottom-color: green; */}.triangle-part:nth-child(5) {transform: rotate(240deg);/* border-bottom-color: blue; */}.triangle-part:nth-child(6) {transform: rotate(300deg);/* border-bottom-color: purple; */}</style>
</head><body><h1>三角形</h1><div class="single-triangle"></div><h2>正六边形</h2><div class="hexagon-container"><div class="hexagon-triangle"></div><div class="hexagon-triangle"></div><div class="hexagon-triangle"></div><div class="hexagon-triangle"></div><div class="hexagon-triangle"></div><div class="hexagon-triangle"></div></div><h1>五角星</h1><svg width="100" height="100" viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"><polygon points="100,10 40,198 190,78 10,78 160,198" style="fill:red;stroke:red;stroke-width:1" /></svg><h1>六角星</h1><div class="shape-holder"><div class="triangle-part"></div><div class="triangle-part"></div><div class="triangle-part"></div><div class="triangle-part"></div><div class="triangle-part"></div><div class="triangle-part"></div></div><script>// 错误处理:确保浏览器支持 CSS transformif (!('transform' in document.body.style)) {alert('您的浏览器不支持 CSS transform,无法正常显示效果。');}</script>
</body></html>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词