HTML: Painting a triangle with CSS

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.