css less 深入剖析

26
CSS LESS 深深深深 Howard 2014/01/27

Upload: learningtech

Post on 15-May-2015

259 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Css less 深入剖析

CSS LESS 深入剖析

Howard 2014/01/27

Page 2: Css less 深入剖析

Guildline• Variables• Mixins• Nested Media Queries ( 略 )• Advanced Usage of & ( 略 )• Scope ( 略 )• Extend• Namespaces• Parametric Mixins• String interpolation• Selector Interpolation

Page 3: Css less 深入剖析

Variables

Page 4: Css less 深入剖析

Mixins• In LESS, it is possible to include a bunch of

properties from one ruleset into another ruleset. So say we have the following class:

Page 5: Css less 深入剖析

Mixins• "mix-in" properties from existing styles• You can mix-in class selectors and id selectors,

e.g.

Page 6: Css less 深入剖析

Mixins• When you call the mixin, the parenthesis are

optional.

Page 7: Css less 深入剖析

Not outputting the mixin

• If you want to create a mixin but you do not want that mixin to be output, you can put parenthesis around it.

Page 8: Css less 深入剖析

Selectors in mixins• Mixins can contain more than just properties,

they can contain selectors to.

Page 9: Css less 深入剖析

Mixins With Multiple Parameters

• Parameters are either semicolon or comma separated. It is recommended to use semicolon.

• The symbol comma has double meaning: o It can be interpreted either as a mixin parameters

separator o As css list separator.

Page 10: Css less 深入剖析

Mixins With Multiple Parameters• two arguments and each contains comma

separated list

Page 11: Css less 深入剖析

Mixins With Multiple Parameters• three arguments and each contains one number

Page 12: Css less 深入剖析

Mixins With Multiple Parameters• use dummy semicolon to create mixin call with

one argument containing comma separated css list

Page 13: Css less 深入剖析

Mixins With Multiple Parameters• comma separated default

value: .name(@param1: red, blue;).

Page 14: Css less 深入剖析

Mixins With Multiple Parameters• It is legal to define multiple mixins with the same

name and number of parameters. Less will use properties of all that can apply.

Page 15: Css less 深入剖析

The Keyword !important

• Use the !important keyword after mixin call to mark all properties brought by it as !important:

Page 16: Css less 深入剖析

Mixin Guards• Guards are useful when you want to match on

expressions, as opposed to simple values or arity.

• The full list of comparison operators usable in guards are: > >= = =< <

Page 17: Css less 深入剖析

Mixin Guards• Guards can be separated with a comma ‘,’–if any

of the guards evaluates to true, it’s considered as a match:

• if you want to match mixins based on value type, you can use the is* functions:

Page 18: Css less 深入剖析

Mixin Guards• Here are the basic type checking functions:

o iscoloro isnumbero isstringo iskeywordo Isurl

• If you want to check if a value, in addition to being a number, is in a specific unit, you may use one of:o ispixelo ispercentageo isemo isunit

Page 19: Css less 深入剖析

Mixin Guards•

Page 20: Css less 深入剖析

略• Nested Queries• Advanced Usage of &• Scope

Page 21: Css less 深入剖析

Extend• As of version 1.4, LESS supports extending a

style.

• it adds the extending selector to the selector list for output of the extended class.

• The syntax for extend is designed to mimic the syntax of CSS pseudo-classes, and can be combined with pseudo-classes as long as any extends selectors come last.

Page 22: Css less 深入剖析

Namespaces• If you want to mixin properties inside a more

complicated selector, you can stack up multiple id's or classes.

• again the > is optional

Page 23: Css less 深入剖析

Namespaces•

Page 24: Css less 深入剖析

String interpolation• Variables can be embedded inside strings in a

similar way to Ruby or PHP, with the @{name} construct:

Page 25: Css less 深入剖析

Selector Interpolation• If you want to use LESS variables inside selectors,

you can do this by referencing the variable using @{selector} as in string interpolation. For example: