Use CSS border attributes to draw triangles. cssborder

Source: Internet
Author: User

Use CSS border attributes to draw triangles. cssborder

Effect



HTML:

<! Doctype html>
<Html lang = "en">
<Head>
<Meta charset = "UTF-8">
<Title> CSS Triangle Demo </title>
<Link rel = "stylesheet" href = "triangle.css">
</Head>


<Body>
<H3> Down Triangle <Div class = "down-triangle">
</Div>

<H3> Up Triangle <Div class = "up-triangle">
</Div>

<H3> Left Triangle <Div class = "left-triangle">
</Div>

<H3> Right Triangle <Div class = "right-triangle">
</Div>
</Body>
</Html>



CSS :( triangle.css)

. Down-triangle {
Width: 0;
Height: 0;
Border-width: 10px 10px 0 10px;
Border-style: solid;
Border-color: # dc291e transparent;
}

. Up-triangle {
Width: 0;
Height: 0;
Border-width: 0px 10px 10px 10px;
Border-style: solid;
Border-color: # dc291e transparent;
}

. Left-triangle {
Width: 0;
Height: 0;
Border-width: 10px 10px 10px 0px;
Border-style: solid;
Border-color: transparent # dc291e;
}

. Right-triangle {
Width: 0;
Height: 0;
Border-width: 10px 0px 10px 10px;
Border-style: solid;
Border-color: transparent # dc291e;
}


Github link: https://github.com/kiwiwin/css-demotriangle-demo


Border attributes in css

Border: 1px solid #000; you can set the style width and color of the top right bottom left border at the same time.
Border-style: solid; set the style of the upper right bottom left border
Border-width: 1px 2px 3px 4px; set the width of the upper right bottom left border
Border-color: #000; set the color of the upper right bottom left border
Border-top: 1px solid #000; set the style width and color of the upper border
Border-right: 1px solid #000; set the style width and color of the right border
Border-bottom: 1px solid #000; set the style width and color of the bottom border
Border-left: 1px solid #000; set the style width and color of the left border

Of course, you can expand a few more

Q: How does css implement a downward triangle border (border )? If you do not understand, see the following example.

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "www.w3.org/..al.dtd">
<Html xmlns = "www.w3.org/5o/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> Triangle using the border attribute of css </title>
<Style type = "text/css">
<! --
. Box {width: 300px; height: 300px; background: # CCC; position: relative; top: 100px; left: 100px}
. To-top {display: block; overflow: hidden; width: 0px; height: 0px; border: 6px solid # ccc; border-color: # ccc # fff; border-width: 0 6px 6px; position: absolute; left: 30px; top: 0; margin-top:-6px ;}
. To-right {display: block; overflow: hidden; width: 0px; height: 0px; border: 6px solid # ccc; border-color: # fff # ccc; border-width: 6px 0 6px 6px; position: absolute; right: 0px; top: 30px; margin-right:-6px ;}
. To-bottom {display: block; overflow: hidden; width: 0px; height: 0px; border: 6px solid # ccc; border-color: # ccc # fff; border-width: 6px 6px 0 6px; position: absolute; right: 30px; bottom: 0; margin-bottom:-6px ;}
. To-left {display: block; overflow: hidden; width: 0px; height: 0px; border: 6px solid # ccc; border-color: # fff # ccc; border-width: 6px 6px 6px 0; position: absolute; left: 0; bottom: 30px; mar ...... remaining full text>

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.