css realizes up, down, left and right triangle

Write a div

<div class="triangle"></div>

1. Improvement

Insert picture description here

.triangle{
    
    
	width:0;
        height:0;
	border-right:50px solid transparent;
	border-left:50px solid transparent;
	border-bottom:50px solid red;
}

2. Down

Insert picture description here

.triangle{
    
    
	width:0;
	height:0;
	border-right:50px solid transparent;
	border-left:50px solid transparent;
	border-top:50px solid red;
}

3. Left

Insert picture description here

.triangle{
    
    
    width:0;
    height:0;
    border-top:50px solid transparent;
    border-bottom:50px solid transparent;
    border-right:50px solid red;
}

4. Right

Insert picture description here

.triangle{
    
    
    width:0;
    height:0;
    border-top:50px solid transparent;
    border-bottom:50px solid transparent;
    border-left:50px solid red;
}

Guess you like

Origin blog.csdn.net/weixin_45895806/article/details/112605153