Click here to return to the webpage tutorial HTML section. Click here to view the CSS tutorial. Above: Markup Language-Simplified labels. Chapter10 applies CSS. In the first part, the main focus is on the tag syntax example. It also discusses how to apply CSS on the tag to design and specify the style details. in chapter 2, we will discuss several types of CSS applications. Click here to return to the HTML tutorial section of the webpage tutorial. click here to view the CSS tutorial. Above: Markup Language-Simplified labels. Chapter 10 applies CSS. In the first part, the main focus is on the tag syntax example. It also discusses how to apply CSS on the tag to design and specify style details. in chapter 2, we will discuss several types of CSS applications. Click here to return to the script home HTML tutorial section. click here to view the CSS tutorial.
Above:
Markup Language-Simplified tag. Chapter 10 apply CSS
The first part focuses on the tag syntax example. It also discusses how to apply CSS to the tag to design and specify the style details. in chapter 2, we will discuss several practices for applying CSS to a document, website, or even a single tag. in addition, we will discuss how to hide CSS content for earlier browsers, so that we can use advanced techniques without affecting the tag structure that can be read by all browsers and devices.
In the "tip extension" unit at the end of this chapter, we will introduce how to change the font, color, and various themes without having to write a script-replace the style sheet. How to Apply CSS to files?
Now we will discuss four different methods to apply CSS to documents. Each method has its own advantages and disadvantages. Depending on the situation, the four methods may be the best choice. each method demonstrated here uses a valid XHTML 1.0 Transitional syntax structure,Tag andConfiguration.
Let's start with method A. Method:
This is also an embedded style sheet that allows you to directly write all CSS statements in (X) HTML files,
Similar to Method B, @ import can be used to import CSS definitions from external files in relative paths (such as in the preceding example) or absolute paths.
Method C and usage Labels share the same advantages. Because style sheets are placed in external documents, modifying and updating a single document can change the entire website and complete the process easily and quickly. the external style sheet will be cached by the browser, saving download time for all pages that import the same style sheet. hide-and-seek
The major benefit of using method C is: Netscape 4. versions earlier than X do not support the @ import syntax. Therefore, the referenced CSS content will be "hidden". This must be a useful technique, because we can use this to write Advanced CSS syntax to process design details such as layout, so that the newest browsers that can be processed can display them, and old browsers can ignore these syntaxes.
Netscape 4. the problem with x is that it thinks its CSS support capability is as good as that of a truly supported browser. therefore, except for Netscape 4. in addition to x, we can make the browser decide whether to display the correct results.
This is the focus of standard website design. We try to separate the structured markup code from the display method, and provide layout details and other styles for supported browsers. old browsers read the structure content that they can easily display, but do not process the advanced CSS rules hidden for them. open Style, close Style
Take a look at 0-1 and 10-2, and compare them. This is my personal website that uses the complete CSS, and then turn off the CSS display effect (it should be very close to the display effect of the old browser ), when CSS is not used, the structure is still very obvious, and everyone is still easy to read and use. if we do not hide the CSS required for the display layout, users of the old browser may obtain a hard-to-read content.
0-2 remove CSS from the same page. The old web browser may display it as a combination of Method B and method C to apply multiple style sheets.
Sometimes it may be useful to introduce many sub-style sheets in a document. For example, you can put all layout rules in one document and set the font to another document, for a large and complex design, this makes it easier to maintain a large number of rules. chameleon Effect
When creating a website for Fast Company Magazine, I want to change the color of the website every month to match the cover pictures of the current magazine. To simplify regular modification, therefore, I concentrated all the color-related CSS rules in one document, and put other rules that will not be modified every month into another document.
Every month, it is simpler and faster to cover all colors, without having to find the content to be changed in the hundreds of other rules that constitute the design. once this document is modified, the color of the entire website changes immediately. how to do it
To introduce multiple style sheets in combination with method B and method C, the procedure is on the pageUsed in The tag is referenced with the CSS main document, which is similar to the BB demonstration and linked to styles.css.
Styles.css only contains several @ import rules to introduce other necessary CSS files.
The contents of the signature may be as follows:
/* Old browsers will not interpret these import rules */
@ Import url ("layout.css ");
@ Import url ("fonts.css ");
@ Import url ("colors.css ");
In this way, the same Label, only the styles.css file is used. This document can continue to import other style sheets according to the @ import rule. The new style sheet can play a role for the entire website as long as it is added to this document.
This makes updating and replacing CSS very simple. For example, if you suddenly want to cut CSS into four files on the road, you only need to modify the @ import rule of this document, instead of modifying all XHTML markup source code. lo-Fi and Hi-Fi styles
Another technique is available when the @ import rule of method C hides CSS from an old browser. that is, the Cascade Effect of CSS is used to provide old Lo-Fi effects supported by method A or method B, and then @ import is used to provide advanced effects for other supported browsers.
Old browsers only get the content they support, while new browsers get all the styles they want to use.
Next let's take a look at the code of this technique:
Http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd>
Applying CSS
This lofi.cssshould include basic cssrules, such as chain colors, font sizes, and hifi.css contains advanced rules, such as layout, positioning, and background images.
We can transmit the style of Lo-Fi and Hi-Fi versions at the same time, without having to write a script or identify the browser version in any way on the server side. The order is very important.
Specify And
Because custom.cssis the second code in the tag source code, the same tag pattern will overwrite the content specified in master.css.
For example, in main.css, the red serif font is required for the label, and the blue serif font is used.
H1 {
Font-family: Georgia, serif;
Color: red;
}
H2 {
Font-family: Georgia, serif;
Color: blue;
}
On a specific page, we only want to change the format of the tag. In custom.css, we only need to declare the new style.
H1 {
Font-family: Verdana, sans-serif;
Color: orange;
}
Override.
The CSS cascade function is a good tool for sharing common styles, allowing you to only overwrite the Rules to be modified. Method D: Intra-row styles
This is a Title
This is our fourth CSS application method-in-row style. Almost any label can add the style attribute, so that you can apply CSS style rules directly to the label, just like in the above example.
Because the intra-row style is the bottom layer of the stack, they will overwrite the declaration of all external styles and the declaration inOf