html - 3 个不同形状的 div 在一起
问题描述
我希望你能帮助我。我有这个想法来创建 3 个不同形状的 div。第一个三角形 第二个菱形 第三个三角形。当它们放在一起时,它们会形成一个矩形。我创建了 3 个 div 数字,但将它们放在一起时遇到了问题。我会感谢你的帮助。
注意:我尝试过 flex,但是主 div 被分成 3 个平行部分。
HTML
.triangle {
width: 80%;
height: 300px;
border: 2px solid black;
margin: 20px auto;
background: grey;
}
.triangle .figure_1 {
width: 50%;
display: inline-flex;
clip-path: polygon(0% 0%, 0% 100%, 100% 100%);
background: green;
}
.triangle .figure_2 {
width: 100%;
clip-path: polygon(0% 0%, 50% 100%, 100% 100%, 50% 0%);
background: yellow;
}
.triangle .figure_3 {
width: 50%;
clip-path: polygon(0% 0%, 100% 100%, 100% 0%);
background: red;
}
<div id="triangle" class="triangle">
<div id="figure_1" class="figure_1">
</div>
<div id="figure_2" class="figure_2">
</div>
<div id="figure_3" class="figure_3">
</div>
</div>
解决方案
试着让你的三角形是相对的,图形是绝对的
.triangle {
width: 80%;
height: 300px;
border: 2px solid black;
margin: 20px auto;
background: grey;
position: relative;
}
.triangle .figure_1 {
width: 50%;
display: inline-flex;
clip-path: polygon(0% 0%, 0% 100%, 100% 100%);
background: green;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.triangle .figure_2 {
width: 100%;
clip-path: polygon(0% 0%, 50% 100%, 100% 100%, 50% 0%);
background: yellow;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.triangle .figure_3 {
width: 50%;
clip-path: polygon(0% 0%, 100% 100%, 100% 0%);
background: red;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
<div id="triangle" class="triangle">
<div id="figure_1" class="figure_1">
</div>
<div id="figure_2" class="figure_2">
</div>
<div id="figure_3" class="figure_3">
</div>
</div>
推荐阅读
- python - 通过 pandas 与 pyarrow 转换模式
- python - 如何转置 pyspark 数据帧?
- laravel - 带有 Laravel 和 Vue2 的 InertiaJS:无法重新定义属性:$inertia
- python-3.x - 函数 - 变量 - 范围
- python - 如何在webelement中迭代标签?
- html - 将 html 编辑按钮添加到 Angular 中
- twitter - Twitter card on subdomain
- apache-flink - 带有状态的 Flink 窗口聚合
- python - 发送带有图形的消息
- python - 错误 Python API GCP 数据目录 - Google Cloud Platform