CSS How to ... (Cont.)


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 by using the <style> tag, like the one on the right. The browser will now read the style definitions, and format the document according to it.
 <head>
  <style type="text/css">
   h3 { color: #3366CC }
   p  { margin-left: 20px }
   body { background-image:
    url("bg.jpg") }
  </style>
 </head>

When a browser reads a style sheet, it will format the document according to it. A browser normally ignores unknown tags.

This means that an old browser that does not support styles, will ignore the <style> tag, but the content of the <style> tag will be displayed. It is possible to prevent an old browser from displaying the content by hiding it in the HTML comment element:
 <head>
  <style type="text/css">
   <!--
    h3 { color: #3366CC }
    p  { margin-left: 20px }
    body { background-image:
     url( "bg.jpg" ) }
   -->
  </style>
 </head>


Inline Styles
An inline style loses many of the advantages of style sheets by mixing content with presentation. Use this method sparingly, such as 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 contain any CSS property. The example shows how to change the color and the left margin of a paragraph:
 <p style="color: #3366CC;
   margin-left: 20px">
   This is a paragraph
 </p>

Demonstration
The following demonstration shows how the script of HTML and CSS is displayed on the Web:

     



Review: CSS (Cascading Style Sheets)
    Which attribute of an HTML tag is used to contain the properties of inline CSS styles?

      CSS
      inline
      property
      style
Result: