CSS use: Before:after write small triangle instance sharing

Source: Internet
Author: User
This article mainly introduces how to use: Before:after write a small triangle of relevant information, small series feel very good, and now share to everyone, but also for everyone to do a reference. Follow the small series together to see it, hope to help everyone.

Previously written triangles are always in the same color, with no border style. As follows:

The CSS code is as follows:

. tri-up{width:0;height:0;border-left:20px Solid transparent;border-right:20px Solid transparent;border-bottom:20px Solid red;  }. tri-left{width:0;height:0;border-top:20px Solid transparent;border-bottom:20px Solid transparent;border-left:20px Solid red;}. tri-right{width:0;height:0;border-top:20px Solid transparent;border-bottom:20px Solid Transparent;border-right: 20px solid red;}. tri-down{width:0;height:0;border-left:20px Solid transparent;border-right:20px Solid transparent;border-top:20px Solid red; }

To write the following small triangle, you need to use Pseudo-class: Before:after

CSS code:

#demo {            margin:100px;;            width:100px;            height:100px;            Background-color: #fff;            position:relative;            border:2px solid #333;        } The style of the box        #demo: After, #demo: before {            border:solid transparent;            Content: ";            height:0;            left:100%;    Depending on the position of the triangle, you can change it arbitrarily.            Position:absolute;            width:0;        }         #demo: after {            border-width:10px;            Border-left-color: #fff;            top:20px;//changes according to the position of the Triangle        }//here is a white triangle        #demo: before {            border-width:12px;            Border-left-color: #000;            top:18px;        } Here is a black triangle//When the style of #demo:after and #demo:before is coincident, because the top value is different in size, you can get the middle is white, but the border of the triangle. Such as.

<p id= "Demo" ></p>

To change the style:

The CSS code is as follows:

#demo {            margin:100px;;            width:100px;            height:100px;            Background-color: #fff;            position:relative;            border:2px solid #333;        }        #demo: After, #demo: before {            border:solid transparent;            Content: ";            height:0;            top:100%;            Position:absolute;            width:0;        }        #demo: after {            border-width:10px;            Border-top-color: #fff;            left:20px;        }        #demo: before {            border-width:12px;            Border-top-color: #000;            left:18px;        }
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: 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.