


Detailed explanation of techniques for drawing triangular arrow patterns using CSS
I want to modify this website recently, and I want to put a prompt box on it. This is easy enough, but I want the tooltip to have a triangular arrow. However, it is almost a disaster when I think about the need to use pictures and prepare countless arrows of various colors and directions. Fortunately, Darren Waddell, the core developer of MooTools, told me about a great technique: drawing triangular arrows with CSS. Using pure CSS, you only need very little code to create triangular arrows that are compatible with various browsers!
CSS code
/* create an arrow that points up */ p.arrow-up { width: 0; height: 0; border-left: 5px solid transparent; /* left arrow slant */ border-right: 5px solid transparent; /* right arrow slant */ border-bottom: 5px solid #2f2f2f; /* bottom, add background color here */ font-size: 0; line-height: 0; } /* create an arrow that points down */ p.arrow-down { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 5px solid #2f2f2f; font-size: 0; line-height: 0; } /* create an arrow that points left */ p.arrow-left { width: 0; height: 0; border-bottom: 5px solid transparent; /* left arrow slant */ border-top: 5px solid transparent; /* right arrow slant */ border-right: 5px solid #2f2f2f; /* bottom, add background color here */ font-size: 0; line-height: 0; } /* create an arrow that points right */ p.arrow-rightright { width: 0; height: 0; border-bottom: 5px solid transparent; /* left arrow slant */ border-top: 5px solid transparent; /* right arrow slant */ border-left: 5px solid #2f2f2f; /* bottom, add background color here */ font-size: 0; line-height: 0; }
The key to drawing these triangles is that you want the two sides in the direction of the arrow to have Very thick borders. The side facing away from the arrow also has the same thick border, and the color of this side is the color of your triangle. The thicker the border, the larger the triangle. This way you can draw arrows of various colors, sizes, and orientations. The best part is, you only need a few lines of CSS code to achieve this effect.
Use :before and :after to draw CSS triangles
The above CSS examples use real page elements to draw, but sometimes the real elements are also It is used, but you can't go on it and operate it directly. What should I do? Pure CSS triangles can actually be drawn using pseudo-elements. Here's how to draw it:
p.tooltip { /* tooltip content styling in here; nothing to do with arrows */ } /* shared with before and after */ p.tooltip:before, p.tooltip:after { content: ' '; height: 0; position: absolute; width: 0; border: 10px solid transparent; /* arrow size */ } /* these arrows will point up */ /* top-stacked, smaller arrow */ p.tooltip:before { border-bottom-color: #fff; /* arrow color */ /* positioning */ position: absolute; top: -19px; left: 255px; z-index: 2; } /* arrow which acts as a background shadow */ p.tooltip:after { border-bottom-color: #333; /* arrow color */ /* positioning */ position: absolute; top: -24px; left: 255px; z-index: 1; }
The color of the border on the side facing away from the arrow is the color of the triangle arrow. You don't need to use both :before and :after pseudo-elements to draw this arrow - one is enough. And the other one, you can use it as a background shadow or background edge for the previous one.
I really should have known about this technology earlier! I believe this simple and hassle-free technology will come in handy when making interface improvements in the future.
The above is the entire content of this article. I hope it will be helpful to everyone's learning. I also hope that everyone will support the PHP Chinese website.
The above is the detailed content of Detailed explanation of techniques for drawing triangular arrow patterns using CSS. For more information, please follow other related articles on the PHP Chinese website!

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



Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

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.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

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

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.
