"Less series" advanced features-pattern matching

Source: Internet
Author: User

I already have an article written in the basic grammar of less.

So this time, let's look at the advanced features of less.

Although the practical degree of the pattern matching is generally the same, but in the key time, have them in the words, or can let us develop more handy.

In fact, the default value of the parameter setting is the simplest pattern match.

You call the Mixins function, pass in the arguments, and do not pass in the parameters, and may have different compilation results.

In addition to that, pattern matching is still the case, let's take a look.

As previously customary, less code and CSS codes were compiled and compiled before compilation.

1. Match different mixins with different number of parameters

/**/. Test (@size){  width: @size;} . Test (@size, @multiple) {  width: @size * @multiple;} . El-a {  . Test (10px);} . El-b {  . Test (10px, 2);}
/**/{  width: 10px;}  {  width: 20px;}

2. Use constant parameters to match different mixins

 /*   less CODE  */ .test (Large, @size: 10px)  { width :  @size * 2 ;} .test (Simple, @size: 10px)  {:  @size ;} .test (@_, @size: 10px)  { display :  block ;} .el-a  {} .el-b  {} 
/**/{  width: 20px;   Display: block;}  {  width: 10px;   Display: block;}

Here's how the whole process happens:

The first. Test is matched only if the large condition is satisfied;

The second. Test is matched only if the simple condition is satisfied;

The third. Test is matched under any condition, even large and simple, as long as the pass-through rule is satisfied (. Test requires passing one or two parameters);

As long as the mixins satisfies the matching requirements, it will be used.

A variable can match any value, and a constant can match successfully only if the value passed in is exactly equal to it.

3.

Less series advanced features-pattern matching

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.