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

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.

主站蜘蛛池模板: 和林格尔县| 龙陵县| 孟连| 石河子市| 湾仔区| 桃园市| 双流县| 成武县| 武川县| 电白县| 和田市| 海阳市| 阳泉市| 上蔡县| 鹿泉市| 马边| 高青县| 宜君县| 南召县| 晋中市| 乐安县| 盈江县| 宜兰县| 丹阳市| 井研县| 天水市| 蒙阴县| 吴川市| 昭平县| 金堂县| 社旗县| 安庆市| 喀喇沁旗| 来凤县| 烟台市| 淮安市| 交口县| 临潭县| 武宣县| 姜堰市| 奇台县|