gpt4 book ai didi

css - 如何在CSS中制作半方形背景

转载 作者:技术小花猫 更新时间:2023-10-29 11:05:45 26 4
gpt4 key购买 nike

square cut in half diagonaly

是否可以像图像上那样在纯 css 背景中制作半个正方形。我知道它可以用图像作为背景来完成,但我需要使用 5 种不同的颜色,也许将来可以更改颜色。

最佳答案

如果您的 div 具有固定大小,您可以使用边框来制作两个三 Angular 形,如 How do CSS triangles work? 中所述。 :

div{
display:inline-block;
border-top:100px solid red;
border-right:100px solid grey;
}
<div></div>

要制作其他尺寸、颜色,您需要调整边框属性:

div {
display: inline-block;
}
div:nth-child(1) {
border-right: 100px solid red;
border-top: 100px solid grey;
}
div:nth-child(2) {
border-left: 100px solid red;
border-top: 100px solid grey;
}
div:nth-child(3) {
border-right: 50px solid red;
border-top: 100px solid grey;
}
div:nth-child(4) {
border-right: 100px solid red;
border-bottom: 50px solid grey;
}
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>

关于css - 如何在CSS中制作半方形背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29819502/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com