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

  • Mastering CSS
  • Rich Finelli
  • 294字
  • 2021-07-08 09:45:45

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.

主站蜘蛛池模板: 高平市| 赤峰市| 大新县| 荣成市| 聂拉木县| 柘荣县| 资中县| 安康市| 诸暨市| 修水县| 万盛区| 民丰县| 长治县| 双辽市| 静海县| 杭州市| 如东县| 安徽省| 宁海县| 瑞安市| 合水县| 巴马| 宁强县| 渝北区| 浑源县| 加查县| 扶沟县| 昌江| 开封县| 白朗县| 鄂尔多斯市| 乌什县| 涡阳县| 色达县| 图片| 凯里市| 和顺县| 夏津县| 静乐县| 德格县| 沙湾县|