For beginners, see three methods to apply CSS to webpages.

Source: Internet
Author: User
Tags html tags

I. In-line
In-row styles use the style attribute directly in html tags.
<P style = "color: red"> text </p>
Set the paragraph text to red.
However, remember that the final HTML should be independent and use the presentation document, so the intra-row style should be avoided anywhere.
II. Internal
The embedded internal style used for the entire page is in the head label, and the style label is surrounded by the style.

The code is as follows: Copy code
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Strict // EN"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
<Html>
<Head>
<Title> CSS Example </title>
<Style type = "text/css">
P {
Color: red;
      }
A {
Color: blue;
      }
</Style>

...
The text of all paragraphs is red and the link is blue.
Like in-row styles, you should keep HTML and CSS separated, so we only have a savior.
III. External
External styles are used throughout a variety of web pages. It is an independent CSS file, as shown below:

The code is as follows: Copy code
P {
Color: red;
}
A {
Color: blue;
}

If the token is saved as webjx.css, the link in the HTML is as follows:

The code is as follows: Copy code
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Strict // EN"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
<Html>
<Head>
<Title> CSS Example </title>
<Link rel = "stylesheet" type = "text/css" href = "webjx.css"/>

...
Other external style methods will be discussed later in the tutorial. It is enough now.
In this tutorial, it will be a good idea to experiment code along the above method. Use a text editor to create a file and save it as "webjx.css" in the html directory.

The code is as follows: Copy code
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Strict // EN"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
<Html>
<Head>
<Title> My first web page </title>
<Link rel = "stylesheet" type = "text/css" href = "webjx.css"/>
</Head>

...
Save the HTML file. Now CSS is linked, but CSS is empty and no content will change the HTML. When you start to learn CSS, you can add code to the CSS file to view the HTML refresh results.

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.