Most of the time we use the triangle effect:
We can use CSS3 to achieve this effect, how to do it? First of all, we define an empty div, set the div width to 0, give the div a 100px border (here is easy to observe), get a square, the color and the definition of the border color is the same, we see the square is actually this div border.
<id= "D1"></div>style: #d1 { width:0; height:0; border:100px solid red; }
Implementation results:
So what does this element now look like for each border? Let's see:
Corresponding Code:
<id= "D1"></div>style: #d1 { width:0; height:0; border-width:50px; Border-style:solid; border-color:red Blue black yellow;
Upper right Down left
}
From the above we found that in fact, the width of the 0 div of each border is a triangle, the actual operation we may only need a triangle, then we just need to hide the unwanted border (with the Transparent property):
For example, I want a downward triangle:
Corresponding Code:
<id= "D1"></div>style: #d1 { width:0; height:0; border-width:50px; Border-style:solid; border-color:transparent transparent transparent;
Upper right lower left }
It can be seen that only the corresponding border hidden, the corresponding border-color order is:
Border-color: Upper right down left; Each color is separated by a space.
A 45-degree triangle:
Corresponding Code:
<id= "D1"></div>style: #d1 { width:0; height:0; border-width:50px; Border-style:solid; border-color:transparent transparent red red;
Border-color:transparent transparent red blue;
}
At the same time we can adjust the width of the corresponding border to adjust the shape of the triangle:
Corresponding Code:
Here we have modified the width of the border below
<id= "D1"></div>style: #d1 { width:0; height:0; border-width:50px; border-bottom-width:150px; Border-style:solid; border-color:transparent transparent red transparent; Border-color:blue green red Black; }
At the same time, we can draw a triangle with rounded corners:
Corresponding Code:
In order to look more comfortable here, add the transparency attribute;
<id= "D1"></div>style: #d1 { width:0; height:0; border-width:50px; Border-style:solid; border-top-left-radius:15px; opacity:0.569; border-color:red transparent transparent red; }
About the production of the triangle is basically these, many times with pseudo-class before, after use will have unexpected effect:
For example, the label of the login window I wrote myself:
CSS3 Implementing triangles