CSS03: Using CSS in webpage

There are three ways you can specify styles to your web page. In this discussion we will see how to use CSS in your page. First and most simple way is to write the style using style tag inside the head section.

<html>
  <head>
    <style>
      h1 {
        color:red;
      }
    </style>
  </head>
  <body>
    <h1>The heading for this page</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
  </body>
</html>

Output shown below will follow this style.

The heading for this page

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Second way of specifying class is is by writing the style attribute of the element. This method is known as inline style. This also will produce same page output as shown above.

<html>
  <head>
    <!-- header is empty -->
  </head>
  <body>
    <h1 style = "color:red">The heading for this page</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
  </body>
</html>

Last and most common way is by linking and external CSS file to HTML page file. The CSS styles are written in external file. Writing style in this way allow us to change style in one file and effects take place in all the HTML file it is linked to. This makes sure all the styles are standardised across the entire website.

For this this example lets call this file simpleStyle.css. It contains style for only one element.

h1 {
  color:red;
}

Now all we need to do is to link the HTML page file to the CSS file.

<html>
  <head>
    <style>
      <link type = 'text/css" href = "simpleStyle.css"/>
    </style>
  </head>
  <body>
    <h1>The heading for this page</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
  </body>
</html>

Comments

Popular posts from this blog

Drawing Simple Pie Chart

VB.net connecting to SQL Server

VB.net