CSS implementation triangles and application examples

Source: Internet
Author: User

CSS implementation of the triangle, on-line talk a lot, but I found that generally are triangular upward or downward, left to right these two directions seem to speak very little, I tried a bit, found that the original in IE very difficult to engage ~ ~ (Evil IE) ... The
CSS implementation of the triangle principle is: When the width of the element is 0, the border (border) is not 0 o'clock, four corners of the border overlapping 45 degrees angle evenly divided. It's a very awkward speech. Last Picture:
           . Triangle {                
                 border-color:red green Blue pink;
                Border-style: Solid
                Border-width: 20px 20px 20px 20px;
                width:0;
                height:0;
           }

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


So, what do we find when we leave a border?

. triangle {
border-color:red transparent transparent transparent;
Border-style:solid;
border-width:20px 20px 0px 20px;
width:0;
height:0;
}



How? Out of the Bar ~ ~

In the same way, we change to a left-to-right

Left:. Triangle {
Border-color:transparent red transparent transparent;
Border-style:solid;
border-width:20px 20px 20px 0px;
width:0;
height:0;
}

Right:. Triangle {
Border-color:transparent transparent transparent red;
Border-style:solid;
border-width:20px 0px 20px 20px;
width:0;
height:0;
}

The merit is caused!? Slow, what kind of browser do you use? If you use non-IE6 words, congratulations! Below we use IE6 (gnashing of teeth ing ... ),



Sweat ~ ~ ~

Originally, IE6 default to the background black ~ ~

Only with the use of IE proprietary East, to solve the bell need to ring people (~_~)

First of all, CSS hack, with the underscore "_"!

_border-top-color:white;
_border-bottom-color:white;
Then use chroma filter: _filter:chroma (color =white);

In fact, it is to filter off the edge!

also add font-size:0; line-height:0;

This completely removes the black background:

. triangle {
Border-color:transparent transparent transparent red;
Border-style:solid;
border-width:20px 0px 20px 20px;
font-size:0;
line-height:0;
width:0;
height:0;
_border-top-color:white;
_border-bottom-color:white;
_filter:chroma (color =white);
}


HTML+CSS:

JS Code
  1. <! DOCTYPE HTML public "-//W3C//DTD html 4.01//en" " http://www.w3.org/TR/html4/strict.dtd" >
  2. <meta http-equiv="Content-type" content= "text/html; Charset=utf-8 ">
  3. <title>css Triangle </title>
  4. <style>
  5. . tiparrow {
  6. / * Color on right, other transparent * /
  7. Border-color:transparent #e00 Transparent transparent;
  8. Border-style:solid;
  9. border-width:6px 6px 6px 0px;
  10. padding:0;
  11. width:0;
  12. height:0;
  13. / * IE6 height fix * /
  14. font-size:0;
  15. line-height:0;
  16. / * IE6 transparent fix * /
  17. _border-top-color: #dddddd;
  18. _border-bottom-color: #dddddd;
  19. _filter:chroma (color = #dddddd);
  20. }
  21. </style>
  22. <body>
  23. <div class="Tiparrow"/>
  24. </div>
  25. </body>

Know some students to directly see the effect, haha: look

Download

The triangle is coming out, so let's look at an example of the application (combining the previously written fadein,fadeout):

Http://kingkit.com.cn/KUI/Tip.html

Full Package

    • Triangle3.rar

CSS implementation triangles and application examples

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.