Parameter Mixing
Just like having function functions in CSS, these functions are useful for unnecessary work in current CSS work. The best and most useful example is the private prefixes of many browsers that we are experiencing during the transition from CSS2 to CSS3. Nettuts + has a great video and article written by Jeffrey Way, which contains files composed of useful parameters. They cover most of the CSS3 attributes that use private prefixes of various browsers. For example, in their format, a mixin that simply processes rounded corners is as follows:
. Border-radius (@ radius: 3px) {-webkit-border-radius: @ radius;-moz-border-radius: @ radius ;}
In this example,. border-radius has a default 3px rounded corner, but you can use any value you need .. Border-radius (10px) generates a rounded corner with a radius of 10px.
The syntax in Sass is similar to LESS. It only uses $ to declare the variable, and then uses the @ mixin and @ include mentioned above to call it.
Selector inheritance
This things LESS is not provided. With this function, you can attach a selector to a pre-defined selector without using commas to separate the two:
. Menu {border: 1px solid # ddd ;}. footer {@ extend. menu;}/* the preceding writing rules have the same effect as the following :*/. menu ,. footer {border: 1px solid # ddd ;}
Nested rules
Nesting classes and IDs in css is the only way to avoid style interference or other style interference. However, this may be messy. Using a selector similar to # site-body. post. post-header h2 is unattractive and occupies a large number of unnecessary spaces. With LESS, you can nest IDs, classes, and labels. For the example mentioned above, you can write as follows:
# Site-body {... . Post {... . Post-header {... H2 {... } {... & Amp;: visited {... } & Amp;: hover {... }}}}}
The above code is eventually the same as the above example (that long string of selectors), but it is easier to read and understand, and occupies a small amount of space. You can also reference element styles to their pseudo elements through &. this function is similar to this in JavaScript.
Operation
This may be what you expected: use numbers or variables to perform mathematical operations in your style sheet!
@ Base_margin: 10px; @ double_margin: @ base_margin * 2; @ full_page: 960px; @ half_page: @ full_page/2; @ quarter_page: (@ full_page/2)/2;
Under the Declaration, I also realized that I could divide it by 4 to get the @ quarter_page variable, but here I just want to demonstrate that parentheses form the "Operation Order", which is also usable here. In the abbreviated rule, parentheses are also required, for example, border: (@ width/2) solid #000.
Sass is more professional in numbers than LESS. It can be converted into units. Sass can process unidentifiable measurement units and output them. This feature is clearly an attempt to the future-proving some of the changes made by W3C.
/* Sass */2in + 3 cm + 2 pc = 3.514in/* LESS */2in + 3 cm + 2 pc = Error