Make arrows with CSS pseudo-elements

Source: Internet
Author: User

Now let's start making arrows!

Before you start, you need to know how to use CSS to draw a triangle, if it is not clear you can look at the pure CSS painting all kinds of graphics

We use two CSS pseudo-elements,before and after, which belong to inline elements, but can be changed with display, before and after are new features in CSS2 (now old), browsers are not aware of their compatibility.

The implementation code is as follows:

1 <!--CSS style, in the project can put the same property and attribute value pairs are written together, here is easy to learn -2 <style>3 . Divtest{4 position:Absolute;5  Left:100px;6 Height:40px;7 width:200px;8 Padding-left:30px;9 background:Red;Ten Line-height:40px; One } A . Divtest:before{ - content:"'; - position:Absolute; the Top:0; -  Left:-20px; - Height:0; - width:0; + Border-top:20px Solid RGB (255, 0, 0); - Border-left:20px Solid #FFFFFF; +     /*border-right:20px solid #AF9E9E;*/ A Border-bottom:20px Solid #FF0000; at background:Red; - } - . Divtest:after{ - content:"'; - position:Absolute; - Top:0; in  Right:-20px; - Height:0; to width:0; + Border-top:20px Solid RGB (255, 255, 255); - Border-left:20px Solid #FF0000; the     /*border-right:20px solid #AF9E9E;*/ * Border-bottom:20px Solid #FFFFFF; $ background:Red;Panax Notoginseng } - </style> the <Body> + <Divclass= "Divtest"> A This is an arrow the </Div>

This is an arrow

Here with the CSS pseudo-elements to achieve the front and back two small triangles, a white a red, respectively, added to the div block elements before and after, it becomes an arrow. Of course, the following arrows can also be implemented as a minor modification

This is an arrow

In addition to these, you can add styles to these arrows, such as gradients, projections, margins, rotations, etc.

Here is the code for the border, and look at the allocation principle at the edge:

1 <style>2 . Divtest1{3 width:0;4 Height:0;5 Border-top:40px Solid Blue;6 Border-left:40px Solid Red;7 Border-right: 40px solid Yellow;8 Border-bottom:40px Solid Green;9 }Ten </style> One <Divclass= "Divtest1">&nbsp;</Div>


In this example, we can better understand the border.

Make arrows with CSS pseudo-elements

Related Article

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: 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.