20. HTML CSS Styles

HTML CSS Styles

Styles in HTML
How to Use Styles
Styles Tags

Styles in HTML

With HTML 4.0 all formatting can be moved out of the HTML document and into a separate style sheet.

<html>
<head>
<style type="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>

Nonunderlined Link

<html>
<body>
<a href="lastpage.htm" style="text-decoration:none">
THIS IS A LINK!
</a>
</body>
</html>

Link to an External Style Sheet

<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>I am formatted with a linked style sheet</h1>
<p>Me too!</p>
</body>
</html>

How to use styles

When a beowser reads a style sheet, it formates the document according to the instructions in the sheet.
There are three types of style sheets: external,internal, and inline.

External Style Sheets

External style sheet is ideal when the style is applied to many pages.
With an external style sheet, you can change the look of an entire web site by changing one file.
Each page must link to the style sheet using the <link> tag.
The <link> tag goes inside the <head> section.

<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>

Internal Style Sheet

An internal style sheet should be used when a single document has a unique style.
You define internal styles in the <head> section with the <style> tag.

<head>
<style type="text/css" >
body{background-color:gray}
p{margin-left:20px}
</style>
</head>
<p>The left margin is indented 20 pixels.</p>

Inline Styles

An inline style should be used when a style is to be applied to a single occurrence of an element.
To use inline styles, you use the style attribute in the relevant tag.
The style attribute can containe any CSS property.

<p style="color:red; margin-left:20px">
This is a paragraph. It's colored red and indented 20px.
</p>

Style Tags

TAG Description
<style> Defines a style definition
<link> Defines a resource reference
<div> Defines a section in a document
<span> Defines a section in a document
<font> Deprecated. Use styles instead
<basefont> Deprecated. Use styles instead
<center> Deprecated. Use styles instead

No comments:

My Favorite Books

  • C and Data Structures by Ashok N. kamthane
  • Web Technologies by A. A. Puntambekar
  • Learn HTML and CSS with W3Schools
  • Learn JavaScript and Ajax with W3Schools
  • HTML5 Black Book: Covers Css3, Javascript,XML, XHTML, Ajax, PHP And Jquery
  • HTML5 Application Development Fundamentals: MTA Exam 98-375
  • .NET 4.0 Programming 6-In-1, Black Book
  • SQL Server 2008 R2 Black Book
  • Asp.net 4.0 Projects Covers: net 3.5 And .net 4.0 Codes, Black Book
  • UNIX Shell Programming 1 Edition by Yashavant Kanetkar
  • UNIX and Shell Programming 1 Edition by Richard F. Gilberg, Behrouz A. Forouzan
  • Computer Networks by Andrew S. Tanenbaum
  • Multiple Choice questions in computer science by Timothy J Williams