CSS tutorial: how to add CSS to a webpage

Source: Internet
Author: User

The previous article introduced CSS syntax

We can use the following four methods to apply CSS to HTML files:



Inline)
Embedded Application (Embed) embedded application (Embed)
External connector Link)
Import)
Apply in-row
We can directly declare the format in an HTML file. We can directly declare styles in HTML files. For example,

<P style = 'font-family: verdana; font-size: 16; '> This is font size 16. </p> <p style = 'font-family: verdana; font-size: 16; '> This is font size 16. </p>



The preceding HTML file appears in the browser as follows:

This is font size 16. This is font size 16.

Embedded Application
The format can be embedded in HTML files (usually in
<Head>
<Style type = "text/css"> <style type = "text/css">
Div {
Background-color: # FF0000;
}
</Style>
</Head>

<Body>
<Div>
Background colors: background colors: red
</Div>
</Body>



The above HTML will appear: The above HTML will show:



Background colors: background colors: red
External connector for external connection
In this way, all CSS-like statements are stored in another example. In this way, all CSS style announcements are stored in another file. The common name is ".css. The file is commonly named .css. In the HTML file's
<Link rel = stylesheet type = "text/css" href = "external-stylesheet.css"> <link rel = stylesheet type = "text/css" href = "external-stylesheet.css">

Add the HTML file as declared in the external-stylesheet.css case. In this line, the styles declared in the file external-stylesheet.css will be added to the HTML file.


External CSS styles can also be embedded into HTML files. External CSS styles can also be imported into HTML files. Using the @ import command. The import method is to use the @ import command. @ Import Syntax:

<Style type = "text/css"> <style type = "text/css">
<! --
@ Import url (http://www.mysite.com/style.css );
-->
</STYLE>

@ Import command was originally intended to run in a different manner for different zookeeper devices. @ Import command was originally intended to apply different styles to different browsers. However, this is not necessary now. However, this is no longer necessary. The purpose of @ import is to add multiple CSS styles. The purpose of @ import is to add multiple CSS styles. When multiple CSS styles are added in @ import mode, and different CSS styles are abrupt, the added CSS format has a leading position (for details, see CSS concatenation ). When multiple CSS styles are added in @ import mode and different CSS styles conflict with each other, the added CSS styles take precedence (for details, see CSS concatenation ).

Next we will introduce media categories

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.