The codes are as follows:
<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"Xml:lang= "en"><Head> <Metahttp-equiv= "Content-type"content= "Text/html;charset=utf-8"> <title>Draw a triangle with CSS</title> <style>#triangle{width:0;Height:0;Border-top:100px Solid Green;Border-right:100px Solid Red;Border-bottom:100px solid Black;Border-left:100px Solid Blue; } </style></Head><Body> <DivID= ' triangle '></Div></Body></HTML>
The effect is as follows:
A few notes: div width, height is 0, and the width of the Div border is set, this time you can see four triangles, then which triangle we want to take, we need to make the other triangular border of the color transparent?
Why is it transparent, not white??
Because if it is white, and the triangle is in the same region with the background color, then in the triangular region will be covered with the background color.
The following images:
The triangular white part is covered with the background color! error!
So how do you make the border transparent??
The answer is the implied value of Border-color: Transparent
<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"Xml:lang= "en"><Head> <Metahttp-equiv= "Content-type"content= "Text/html;charset=utf-8"> <title>Draw a triangle with CSS</title> <style>div.bg{Background-color:Maroon;Height:500px; }#triangle{width:0;Height:0;Border-top:100px Solid Transparent;Border-right:100px Solid Transparent;Border-bottom:100px solid Black;Border-left:100px Solid Transparent; } </style></Head><Body> <Divclass= ' BG '> <DivID= ' triangle '></Div> </Div></Body></HTML>
The effect is as follows:
Triangle success, now you can make a model, such as tips,warnings.
HTML: Painting a triangle with CSS