HTML Advanced Programming (4)--html style

Source: Internet
Author: User
Tags deprecated

By using HTML4.0, all the formatting code can be moved out of the HTML document and then moved into a separate style sheet.

Instance
Styles in HTML
This example shows how to format HTML using style information added to the
<HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=gb2312" /><Metahttp-equiv= "Content-language"content= "ZH-CN" /></Head><Head><styletype= "Text/css">H1{Color:Red}H3{Color:Blue}</style></Head><Body><H1>This is header 1.</H1><H3>This is header 3.</H3></Body></HTML>

View results:

No underlined links
This example shows how to use style attributes to make a link that is not underlined.
<HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=gb2312" /><Metahttp-equiv= "Content-language"content= "ZH-CN" /></Head><Body><ahref=".. /example/html/lastpage.html "Tppabs= "http://www.w3school.com.cn/example/html/lastpage.html"style= "Text-decoration:none">this is a link! </a></Body></HTML>

View results:

Linking to an external style sheet
This example shows how to link a <link> tag to an external style sheet.
<HTML><Head><Linkrel= "stylesheet"type= "Text/css"href=".. /html/csstest1.css "Tppabs= "Http://www.w3school.com.cn/html/csstest1.css" ></Head><Body><H1>I format it through an external style sheet.</H1><P>Me too!</P></Body></HTML>

View results:

How to use Styles

When the browser reads a stylesheet, it formats the document according to the style sheet. There are three ways to insert the style sheet:

External style sheet

An external style sheet is an ideal choice when the style needs to be applied to many pages. With an external style sheet, you can change the appearance of the entire site by changing a file.

< Head > <  rel= "stylesheet"  type= "text/css"  href= "Mystyle.css"  ></head>
Internal style sheet

An internal style sheet can be used when a particular style is required for a single file. You can define an internal style sheet in the head section through the <style> tag.

<Head><styletype= "Text/css">Body{Background-color:Red}P{Margin-left:20px}</style></Head>
inline style

Inline styles are used when special styles need to be applied to individual elements. The way to use inline styles is to use style attributes in related tags. Style properties can contain any CSS properties. The following example shows how to change the color and left margin of a paragraph.

<style= "color:red; margin-left:20px">This isa paragraph </ P >

Visit our CSS tutorials to learn more about styling.

label Description
<style> Defines a style definition.
<link> Defines a resource reference.
<div> Defines a section or area (block-level) in a document.
<span> Defines a small block or area within a line in a document.
<font> Specifies the font, font size, and font color of the text. Do not approve of use. Please use a style.
<basefont> Defines the base font. Do not approve of use. Please use a style.
<center> Centers the text horizontally. Do not approve of use. Please use a style.

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.