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

Dissecting a rule set

Let's jump into a CSS file and look at one of the rule sets in the following code block. It's targeting an h2-a level two headline. It's setting a font-size of 26px, a font-style of italic, a color to a shade of red, and a margin-bottom of 10px:

h2 { 
  font-size: 26px; 
  font-style: italic; 
  color: #eb2428; 
  margin-bottom: 10px; 
} 

So nothing too scary here! Let's dissect this a little bit though:

selector { 
  property: value; 
property: value;
property: value; }

In the preceding code, h2 is the selector. We are selecting an element on the page to target our style rules. The h2 selector could be a p, an li, a div, an a, or any HTML element we want to target. It can also be a class, an ID, or an element attribute, which I'll talk about later. Next, we have properties and values inside the curly braces. From the opening curly brace to the closing curly brace is the declaration block. You can have as many properties as you want inside the curly braces, or declaration block. font-size, color, font-style, and margin are just a few of the many different properties that you can use. Each property has a corresponding value. Between each property and value, you must have a colon. Following the value is a semi colon, which is also mandatory. Each property and value is called a declaration. So the declaration block is everything inside the curly braces and a declaration is a single line that includes a property and a value. But really, there are three important things to remember in the anatomy of a rule set: the selector, the property, and the value. Now let's look at where we can write these rule sets.

主站蜘蛛池模板: 秭归县| 清水河县| 肥西县| 苏尼特左旗| 屯昌县| 兴仁县| 仲巴县| 来凤县| 丰县| 基隆市| 冕宁县| 鸡东县| 阿拉尔市| 霍城县| 南陵县| 腾冲县| 天等县| 徐汇区| 化德县| 温宿县| 青阳县| 准格尔旗| 大埔县| 榆社县| 那坡县| 沙雅县| 阿尔山市| 分宜县| 田东县| 明溪县| 尖扎县| 武强县| 怀安县| 东阳市| 屯昌县| 勐海县| 云林县| 乌拉特前旗| 石泉县| 屏边| 阿克陶县|