Several methods of embedding CSS in HTML documents

Source: Internet
Author: User

There are three ways to embed CSS in HTML: embedded, inline, and quoted.

First, embedded

Use the style element in your HTML document to define CSS styles.

1 <Head>2  <styletype= "Text/css">3 H1{Color:Red}4 H2{Color:Blue}5  </style>6 </Head>

Two, inline type

The Style property can be defined in each element of the HTML, and this property can only work on this element. does not work for other elements.

1 <  style= "color: #FFF; font-size:20;" > Entry Dog Blog Park </p>

Iii. quoted type

1. Using processing instructions

1 <? xml-stylesheet type= "text/css" href= "Css.css " ?> 2 < HTML > 3   < P > Entry Dog Blog Park </p>4</HTML >

The browser loads the Css.css file when it is rendered, but most of the browsing is only useful if the file is saved as. xhtml or. xml format and is not recommended.

2. Using the @import directive

1 < style > 2  /* The following two effects are the same */ 3   @import "Css.css"4  @import url ("Css.css"); 5 </ style >

3. Using the LINK element

1 < Head > 2   <  href= "Css.css"  rel= "stylesheet"  type= "Text/css"  >3</head>

This is the most common method, the href attribute specifies the URL of the style sheet, followed by the designation rel= "stylesheet" type= "Text/css".

4. Linking to a style sheet using the HTTP message header

1 Link: (css.css) rel= "stylesheet"2 equivalent to 3<href  = "Css.css"  rel= "stylesheet"  type= "Text/css">

The link field of the HTTP header has a higher precedence than the link field in the HTML document.

Several methods of embedding CSS in HTML documents

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.