CSS Classes

CSS ClassesThe best way to describe these to you is to just to show you examples, so with the best example possible I will begin, in your CSS file use this code:

div.center {
text-align: center;
}

div.indent {
margin: 20px;
text-decoration: underline;
}

You will see that we have given attributes to 2 of the same tag, in this example I have given different attributes to the div tag. To call up a class you use the class="" attribute. In your HTML page when you put your text between the <div class="center"> TEXT </div> you will see that the text is aligned in the center. When you use the code <div class="indent"> TEXT </div> the text is padded 20 pixels in from the left and the text is underlined. E.G.

This text is centred
This text is 20px from the left and underlined

The codes

<div class="center">This text is centred</div>
<div class="indent">This text is 20px from the left and underlined</div>

You see, when the browser reads the page it sees that the DIV tag is there, it then reads that the div tag wants the class 'center' or 'indent', it then looks through your CSS for the corresponding styles and applies them to it.

You can apply the class to any tag, even the body tag.

Another example

Applying multiple classes to the <p> tag. First of all you must give each p tag a name, the name of the class is the name given after the dot. E.G.

p.centerunderline {   text-align: center;
  text-decoration: underline;
}

All P tags with the class name 'centerunderline' will be aligned in the center of the page and will also be underlined. You see in the CSS code you have p.centerunderline and the class name is the word given after the p. You then call the class by using the code class="". Simple isn't it?

Of course, if you wanted to customize every paragraph on your page you would just use the normal p { style style }. And then for every class it would be <p class="classhere">.


Close    To Top
  • Prev Article-Web Design:
  • Next Article-Web Design:
  • Now: Tutorial for Web and Software Design > Web Design > HTMLCSS > Web Design Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction