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

Inline style sheets

Finally, the third type of style sheet is the inline style sheet. And its not really a style sheet - more like just an inline style. What we could do is write a style attribute actually inside an element in our HTML:

<h2 style=""> 

Inline styles are a little different from external and embedded style sheets that use the traditional rule set; here there's no selector and there's no complete rule set because you're writing it inside an HTML tag. We can enter a font-size of 10px. We write that property and value the same way we do in a rule set and we should cap it with a semicolon:

<h2 style="font-size: 10px;"> 

We can also change the color and cap that with a semicolon:

<h2 style="font-size: 10px; color: deeppink;"> 

Save this, refresh the website, and you can see the result:

This is by far the most inefficient way to write styles. However, writing CSS directly in an HTML element gives it the most weight and will overrule all embedded styles and all external styles that target the same element, unless the !important keyword is used. In Chapter 4, Creating Buttons with Modular, Reusable CSS Classes, and CSS3 in the Specificity Rules section, I dive into cascades and other factors that make certain rules weigh more and override other rules.

Okay, so we have now created a rule set and learned what each part of a rule set is called, specifically, the selector, property, and value. This information will be helpful for you to retain, as I'll use this terminology often. We also reviewed the three different places you can create a style sheet: externally, embedded within the <head> tag, and inline, directly inside of an element. Again, external style sheets are the most efficient because they can control an entire website. This is the only place I write CSS if I can help it. Next, we'll review two more core concepts: the box model and the display property.

主站蜘蛛池模板: 嘉义市| 贵州省| 进贤县| 辽宁省| 阳东县| 巫溪县| 新安县| 巴东县| 荥阳市| 扎鲁特旗| 额敏县| 思茅市| 额尔古纳市| 秦皇岛市| 祁连县| 绩溪县| 房产| 马尔康县| 庐江县| 时尚| 昭平县| 巴青县| 夏津县| 察哈| 塔河县| 吉林市| 肇庆市| 明水县| 平原县| 巫山县| 新巴尔虎右旗| 新竹县| 泾川县| 临猗县| 泗洪县| 新田县| 长寿区| 大理市| 渭源县| 堆龙德庆县| 台湾省|