如何通过CSS使这个形状

时间:2017-12-21 13:46:40

标签: css css3 css-shapes

如何通过css和wirte代码来制作这个形状 https://i.stack.imgur.com/AjlrC.jpg

此代码用于翻译此形状

#base { 
    background: red; 
    display: inline-block;
    height: 55px;
    margin-left: 20px;
    margin-top: 55px; 
    position: relative; 
    width: 100px; 
} 

#base:before { 
    border-bottom: 35px solid red; 
    border-left: 50px solid transparent; 
    border-right: 50px solid transparent; 
    content: ""; 
    height: 0; 
    left: 0; 
    position: absolute; 
    top: -35px; 
    width: 0; 
} 

2 个答案:

答案 0 :(得分:4)

请参阅下文。您可以通过更改-70/70像素的值来摆弄三角形的高度。



.base {
	width: 200px;
	height: 100px;
	position: relative;
	background-color: red;
	margin-top: 100px;
}
.base::before {
	content: "";
	position: absolute;
	top: -70px;
	left: 0;
	border-color: transparent transparent red transparent;
	border-width: 0 100px 70px 100px;
	border-style: solid;
	width: 0;
	height: 0;
}

<div class="base"></div>
&#13;
&#13;
&#13;

答案 1 :(得分:2)

试试这段代码:

#base{ width: 0; height: 0;border-left: 85px solid transparent;border-right: 90px solid transparent;border-bottom: 100px solid red;margin:0;}
#rect{ width: 175px;height: 100px; background: red; margin:0;}