官术网_书友最值得收藏!

Nesting

Nesting elements in pure CSS are a bad deal. They are not friendly, are hard to read, and make us write and repeat a lot of code. Using a CSS preprocessor, you will provide a more friendly reading to any developer; the code auto explains what the CSS is doing and how the classes inherit from others. Look at the magic:

Using the SASS syntax:

$my-link-color: #FF0000;
$my-link-hover: #00FFFF;

ul {
margin: 0;

li {
float: left;
}

a {
color: $my-link-color;

&:hover {
color: $my-link-hover;
}
}
}

Using the same in LESS:

@my-link-color: #FF0000;
@my-link-hover: #00FF00;

ul {
margin: 0;

li {
float: left;
}

a {
color: @my-link-color;

&:hover {
color: @my-link-hover;
}
}
}

One thing you need to know is that the browser does not directly interpret the SASS or LESS syntax. Do you need to convert your code to normal CSS syntax, how could you perform it? In the case of SASS, just type the following command:

$ sass --watch app/sass:public/stylesheets

They both export the same CSS output:

ul { margin: 0; }
ul li { float: left; }
ul a { color: #999; }
ul a:hover { color: #229ed3; }

As you can see, CSS preprocessors provide us a more friendly readability and quick understanding of what the code is doing.

主站蜘蛛池模板: 宁化县| 泾川县| 成武县| 涿鹿县| 巴南区| 友谊县| 夏邑县| 闽侯县| 新营市| 宁乡县| 思南县| 太和县| 高平市| 庆安县| 桐城市| 台安县| 尼玛县| 隆安县| 崇义县| 东兰县| 信阳市| 松桃| 宜宾市| 望江县| 夹江县| 常州市| 乡城县| 通河县| 鹤庆县| 运城市| 犍为县| 略阳县| 巴林右旗| 荥经县| 石城县| 白玉县| 河南省| 德保县| 含山县| 永嘉县| 双鸭山市|