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

  • 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.

主站蜘蛛池模板: 安徽省| 大连市| 胶州市| 阳原县| 浙江省| 伊金霍洛旗| 会宁县| 庐江县| 内江市| 荣昌县| 肇庆市| 定日县| 资阳市| 黎川县| 北京市| 边坝县| 深圳市| 资兴市| 胶南市| 丰台区| 赞皇县| 淳化县| 聂荣县| 博兴县| 疏勒县| 沂南县| 大港区| 南陵县| 罗定市| 昌江| 固安县| 福建省| 吉木萨尔县| 桑日县| 松原市| 威宁| 尤溪县| 江北区| 河东区| 海伦市| 武穴市|