Home > Article > Web Front-end > Markup language - CSS style for web page application_HTML/Xhtml_Web page production
Click here to return to the HTML Tutorial column of the Web Teaching Network. To view CSS tutorials, please click here.
Above: Markup language – streamlined tags.
Chapter 10 Applying CSS
In the first part, the main focus is on markup syntax examples, and also explores how to apply CSS to tags for design and specify styling details. In Chapter 2, we will discuss several ways to apply CSS to tags.
Click here to return to the Script House HTML Tutorial column. To view CSS tutorials, please click here.
Above: Markup language - streamlined tags.
Chapter 10 Applying CSS
In the first part, the main focus is on markup syntax examples, and also discusses how to apply CSS to tags for design and specify styling details. In Chapter 2, we will discuss several ways to apply CSS to a document, website, or even a single tag. In addition, we will also discuss how to hide CSS content from earlier versions of browsers, so that we can use advanced techniques without affecting all browsers. , the markup structure read by the device.
In the "Technical Extension" unit at the end of the chapter, we will introduce how to switch fonts, colors, and create multiple themes without writing scripts - replacing style sheets.
How to apply CSS to documents?
Now let’s explore four different methods of applying CSS to documents. Each method has its own advantages and disadvantages. Depending on the situation, all four methods may be the best. Best choice. Each method demonstrated here uses legal XHTML 1.0 Transitional syntax structure, tag and
This The approach has also become an embedded style sheet, which allows you to write all CSS declarations directly in the (X)HTML file. The
with methods Similar to B, you can use @import to import CSS definitions from external files with relative paths (like the example above) or absolute paths.
Method C has the same advantages as using the tag, because the style sheet is placed in the external document , modifying and updating a single document can change the entire website, and it can be done quickly and easily. External style sheets are cached by the browser, saving download time for all pages that import the same style sheet.
Hide and seek
The major advantage of using method C is that Netscape versions below 4. CSS syntax handles design details such as layout, allowing the latest browsers that can handle it to display them, while also allowing older browsers to ignore these syntaxes.
The problem with Netscape 4.x is: it thinks it can support CSS It is only as good as the browser that actually supports it. Therefore, except for Netscape 4. The markup code is separated from the display, and provides layout details and other styles for supported browsers. Older browsers can easily read the displayed structure of the content, but will not process the advanced CSS hidden for them. rule.
Open styles, close styles
Look at Figures 10-1 and 10-2, and compare. This is my personal website using complete CSS, and then turning off the CSS display effect (it should be very close to the display effect of the old browser) Effect), the structure without using CSS is still very obvious, and it is still easy for everyone to read and use. If we do not hide the CSS required to display the layout, then users of older browsers may get a mess that is difficult to read. Content.
Figure 10-1 My personal website, using CSS
Figure 10-2 The same page, remove the CSS, old browsers may change it Displayed like this
Combining Method B and Method C to Apply Multiple Style Sheets
Sometimes, it may be useful to introduce many style sheets into a document. For example, you can put all layout rules into one document and set the font settings. Putting it into another document can make maintaining a large number of rules easier for large, complex designs.
Chameleon Effect
When making the website of Fast Company magazine, I hope to change the color of the website every month to match the cover image of the current magazine. In order to simplify the regular modification work, I centralized all the color-related CSS rules into In one document, and put other rules that will not be modified every month into another document.
It will be easier and faster to cover all the colors every month without having to add hundreds of other rules that make up the design Slowly search for content that needs to be changed. As long as this document is modified, the color of the entire website will change immediately.
How to do it
To combine method B and method C to introduce multiple style sheets, the method is to use the tag in the
/*Old browsers will not interpret these import rules*/In this way, the same url can be used throughout the website The tag only references the styles.css file. This document can continue to import other style sheets using the @import rule. As long as the new style sheet is added to this document, it will have an effect on the entire website.
@import url("layout .css");
@import url("fonts.css");
@import url("colors.css");
"http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">Here lofi.css should contain basic CSS rules, such as link color and font size; while hifi.css contains advanced rules, such as layout, positioning, background images, etc.
Applying CSS
h1 {
font-family: Georgia, serif;
color: red;
}
h2 {
font-family: Georgia, serif;
color: blue;
}
h1 {
font-family: Verdana, sans- serif;
color: orange;
}
This is a Title