


css triangle icon compatible with various browsers_html/css_WEB-ITnose
CSS triangle icon compatible with various browsers
On currently popular websites, we often see some small triangle drop-down prompts (drop-down menu at the top of Weibo) , a simple way can be to use a picture instead, but with the development of front-end technology and developers' "nitpicking" about front-end performance, more and more front-end developers are beginning to "return to their original nature" in scenarios where pictures can not be used. To reduce the use of images, another advantage of CSS icons over images is that we can easily customize the size and color of the icons.
Implementing triangle icons with css is not a new technology. There have been many related technical articles before. This article mainly analyzes the problems encountered when using it in actual scenarios and how to avoid these problems.
The basic principles are similar. Here we mainly introduce the use of css border (of course, you can also use the rotation technology of css3, which will not be covered here due to compatibility issues).
css border implementation
The border of a div or element is not a line with height in our intuitive sense, but a equal-height trapezoid or triangle (when the width and height are 0), You can take a look at the effect:
div definition:
<div class="arrow1"></div>
css:
.arrow1{ width: 0px; height:0px; border-width: 30px; border-style: solid; border-color: #007998 #47A447 #3C6AB9 #D2322D; }
Final effect:
You can see that the border in each direction is a triangle, so we only need to set the borders in the corresponding directions to be transparent or hide them to get a triangle in any direction. If we want to get a drop-down icon, we can change the left and right borders of the border to transparent. The css changes are as follows:
.arrow1{ width: 0px; height:0px; border-width: 30px; border-style: solid; border-color: #007998 transparent transparent transparent; }
Take another look at the effect:
Note: The transparent attribute is used to set the background-color option in the background to the background color transparent
bingo! This is the effect we want, but it is a mess under ie6!
The long black frame makes it difficult for people to look directly at it. This is because IE6 does not support the transparent attribute. At this time, we can set the border style of the corresponding area to dashed. Dashed has a large border width. will be hidden. The css is modified as follows:
.arrow1{ width: 0px; height:0px; border-width: 30px; border-style: solid; border-color: #007998 transparent transparent transparent; }
The effect is as follows (view under ie6):
However, it is not over yet, we set a shadow to see the final result Effect:
Even if we see that a triangle we need has been generated, the occupied height of the triangle is still the original height, which will cause the effect of moving up when used with other elements. At this time, we need to set the height of the lower border to 0:
.arrow1{ width: 0px; height:0px; border-width: 30px 30px 0; border-style: solid; border-color: #007998 transparent transparent transparent; }
Let’s take a look at the effect:
still seems not very friendly when used. We still need to modify the corresponding color. Can we display the corresponding color according to the color set by the parent element? We need to modify the border-color:
.arrow1{ width: 0px; height:0px; line-height: 0px; border-width: 30px 30px 0; border-style: solid dashed dashed dashed; border-left-color: transparent; border-right-color: transparent; }
Effect (using the current font color):
Of course, in addition to using css border generation, we You can also use the special character ◇ to generate overlay positioning, or you can use CSS3 rotation to generate it (hack processing is required under IE6). Using borders is a common and simple and compatible way

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.
