
您可以在 github 仓库中找到这篇文章中的所有代码。
您可以在此处查看 codesandbox 的视觉效果。
如何在 css 中绘制正方形、梯形、三角形、异形三角形、扇形、圆形、半圆、固定宽高比、0.5px 线?
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<title>shapes</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div class="square"></div>
<div class="trapezoidal"></div>
<div class="triangle"></div>
<div class="ano-triangle"></div>
<div class="sector"></div>
<div class="circle"></div>
<div class="half-circle"></div>
<div class="fixed-width-height-ratio"></div>
<div class="half-one-px-line">0.5px line</div>
</body>
</html>
.square {
width: 100px;
height: 100px;
border-top: 50px solid red;
border-bottom: 50px solid blue;
border-right: 50px solid green;
border-left: 50px solid orange;
}
.trapezoidal {
width: 100px;
height: 100px;
border: 50px solid transparent;
border-bottom-color: tomato;
}
.triangle {
width: 0;
height: 0;
border: 50px solid transparent;
border-bottom-color: tomato;
}
.sector {
width: 0;
height: 0;
border: 50px solid transparent;
border-bottom-color: tomato;
border-radius: 50%;
}
.circle {
width: 100px;
height: 100px;
border-radius: 50%;
background-color: tomato;
}
.half-circle {
width: 100px;
height: 50px;
background-color: tomato;
border-top-left-radius: 50px;
border-top-right-radius: 50px;
}
.fixed-width-height-ratio {
padding-top: 56.25%;
background-color: blue;
width: 100%;
}
.half-one-px-line {
background-color: aqua;
border-bottom: 1px solid black;
transform: scaleY(0.5) scaleX(0.5);
transform-origin: 0 0;
}
以上就是形状 - CSS 挑战的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号