What makes up a css rule




















Combined with other style sheets one fundamental feature of CSS is that style sheets are combined , the rule will determine the final presentation of the document. For maximum flexibility, we recommend that authors specify external style sheets; they may be changed without modifying the source HTML document, and they may be shared among several documents.

To link to an external style sheet, you can use the LINK element:. To show the close relationship between a style sheet and the structured markup, we continue to use the STYLE element in this tutorial.

Since no color has been specified for the P element, it will inherit the color from its parent element, namely BODY. In CSS there are often such conflicts between different values, and this specification describes how to resolve them. CSS 2. If that font is not available, the user agent often referred to as a "browser" will use the 'sans-serif' font family which is one of five generic font families which all users agents know.

Child elements of BODY will inherit the value of the 'font-family' property. The second declaration sets the font size of the BODY element to 12 points. The "point" unit is commonly used in print-based typography to indicate font sizes and other length values. It's an example of an absolute unit which does not scale relative to the environment.

The third declaration uses a relative unit which scales with regard to its surroundings. The "em" unit refers to the font size of the element. In this case the result is that the margins around the BODY element are three times wider than the font size. In fact, XML depends more on style sheets than HTML, since authors can make up their own elements that user agents do not know how to display.

Element names in XML are case-sensitive, so a selector written in lowercase e. Still, the text is not formatted the way you would expect. For example, the headline font size should be larger than then the rest of the text, and you may want to display the author's name in italic:.

A visual user agent could format the above example as: [D] Adding more rules to the style sheet will allow you to further describe the presentation of the document. This section presents one possible model of how user agents that support CSS work. This is only a conceptual model; real implementations may vary. In this model, a user agent processes a source by going through the following steps:. In this tutorial you examined all the components that are needed to write a complete CSS rule, including the selector, declaration block, properties, and values.

Where would you like to share this to? Twitter Reddit Hacker News Facebook. Share link Tutorial share link. Sign Up. DigitalOcean home. Community Control Panel. Hacktoberfest Contribute to Open Source. About the authors. Erin Glass. Still looking for an answer?

If you look at a CSS file, you will see that, like any markup or coding language, these files have a specific syntax to them. Each style sheet is made up of a number of CSS rules.

These rules, when taken in full, are what styles the site. A CSS rule is made up of two distinct parts — the selector and the declaration. The selector determines what is being styled on a page, and the declaration is how it should be styled. For example:. This is a CSS rule. The selector part is the p , which is an element selector for "paragraphs. The part of the rule that says, " color: ; " is what is known as the declaration.

That declaration is made up of two pieces — the property and the value. The property is the color piece of this declaration.

It dictates which aspect of the selector will be changed visually. The value is what the chosen CSS property will be changed to. In our example, we are using the hex value of , which is CSS shorthand for "black. So using this CSS rule, our page would have paragraphs displayed in a font-color of black. When you write CSS properties, you cannot simply make them up as you see fit. For instance, "color" is an actual CSS property, so you can use it.

This property is what determines the text color of an element. If you tried to use "text-color" or "font-color" as CSS properties, these would fail because they are not actual parts of the CSS language.

Another example is the property "background-image. If you tried to use "background-picture" or "background-graphic" as a property, they would fail because, once again, these are not actual CSS properties.



0コメント

  • 1000 / 1000