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

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.

主站蜘蛛池模板: 沛县| 三门峡市| 民勤县| 烟台市| 无锡市| 湾仔区| 瑞丽市| 平罗县| 镇赉县| 阜新市| 尼木县| 昭觉县| 临朐县| 泰来县| 堆龙德庆县| 伊通| 玉门市| 泽普县| 大埔县| 霍邱县| 揭阳市| 礼泉县| 德兴市| 龙岩市| 日照市| 当雄县| 资中县| 辽中县| 廉江市| 桑日县| 华容县| 波密县| 昂仁县| 东乡| 太仓市| 五常市| 兰溪市| 兰考县| 平江县| 瑞安市| 郎溪县|