Css implementation triangle and application example, css triangle example
I 've talked a lot about css triangle implementation on the Internet, but I found that the triangle is generally up or down, and the left-to-right direction seems to have little to say. I tried it, it turns out that it is difficult to implement it in IE ~~ (Internet Explorer )...
When the width and height of an element are 0 and the border (border) is not 0, the border of the four corners overlaps with each other to divide the border at 45 degrees. It's awkward to say ~~~ The previous figure:
. 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;
Border-style: solid;
Border-width: 20px 20px 0px 20px;
Width: 0;
Height: 0;
}
How? Come out ~~
In the same way, we change it to the left-to-right,
Left:. triangle {
Border-color: transparent red transparent;
Border-style: solid;
Border-width: 20px 20px 20px 0px;
Width: 0;
Height: 0;
}
Right:. triangle {
Border-color: transparent red;
Border-style: solid;
Border-width: 20px 0px 20px 20px;
Width: 0;
Height: 0;
}
Great success !? Slow, what browser are you using? If you are not using IE6, congratulations! Next we will use IE6 (gnashing teeth ...),
Khan ~~~~
It turns out that IE6 is black by default ~~
Only use the proprietary Internet Explorer, and you need to ring the bell for the solution (~ _~)
First, use the underscore "_" in css hack "_"!
_ Border-top-color: white;
_ Border-bottom-color: white;
Then use chroma filter: _ filter: chroma (color = white );
In fact, it is to filter out unwanted edges!
Also add font-size: 0; line-height: 0;
In this way, the black background is completely removed:
. Triangle {
Border-color: 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
- <! Doctype html public "-// W3C // dtd html 4.01 // EN" "http://www.w3.org/TR/html4/strict.dtd">
- <Html>
- <Head>
- <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
- <Title> css triangle </title>
- <Style>
- . TipArrow {
- /* Color on the right, other transparency */
- Border-color: transparent # e00 transparent;
- Border-style: solid;
- Border-width: 6px 6px 6px 0px;
- Padding: 0;
- Width: 0;
- Height: 0;
- /* Ie6 height fix */
- Font-size: 0;
- Line-height: 0;
- /* Ie6 transparent fix */
- _ Border-top-color: # dddddddd;
- _ Border-bottom-color: # dddddddd;
- _ Filter: chroma (color = # dddddddd );
- }
- </Style>
- </Head>
- <Body>
- <Div class = "tipArrow"/>
- </Div>
- </Body>
- </Html>
I know some of you want to see the results directly. Haha:
Download
The triangle is coming out. Let's look at an example of an application (combined with the fadeIn and fadeOut previously written ):
Http://kingkit.com.cn/KUI/Tip.html
Complete Packaging