Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Inclusion (Css tutorial)

Hello guys! morning to you all and welcome to this section of my tutorial on Cascading Style Sheets (CSS). In my last tutorial i talked about CSS syntax with numerious example. Now in this tutorial i want to talk about the inclusion of Css to our various HTML document i.e how Css is included to HTML documents.

There are four ways to associate styles with your HTML document. Most commonly used methods are inline and External CSS. Now lets look at this four ways of associating styles with HTML documents one after the other.


Embedded CSS - The
 You can put your CSS rules into a HTML document using the



Style Rules
............................



Attributes
 Attributes associated with

Attribute               Value                              Description
type                   text/css          Specifies the style sheet language as 
                                                a content-type (MIME type). This is 
                                                a required attribute. 

media                screen            Specifies the device, the document
                          tty                  will be displayed on. Default value
                          tv                   is all.This is an optional attribute.
                          projection
                          print
                          braille
                          aural
                          all 

Following is a short example of embeded CSS based on the above syntax:



nav {
        color: #000000;
}



Inline CSS - The Style Attribute
You can use style attribute of any HTML element to define style rules. These rules will be applied to that element only. Here is the syntax below:



Attributes

Attribute               Value                              Description
style                  style              The value of style attribute is a
                          rules              combination of style declaration
                                                seperated by semicolon (;).


Example
Following is the example of inline CSS based on the sytax given above:

This is an inline css



External CSS - The Element
The element can be uused to include an external CSS file into your HTML document.
An External Style Sheet is a seperate text file with .css extension. You define all the Style rules within this text file and then you can include this file in any HTML document using element.

Here is the syntax of including external CSS file:



 

Attributes
Attributes associated with elements are:

Attribute               Value                              Description
type                   text/css          Specifies the style sheet language as 
                                                a content-type (MIME type). This is 
                                                a required attribute. 

href                        URL         Specifies the location of the style 
                                                sheet file having style rules. This
                                                attribute is required.

media                screen            Specifies the device, the document
                          tty                  will be displayed on. Default value
                          tv                   is all.This is an optional attribute.
                          projection
                          print
                          braille
                          aural
                          all

Example
Consider a simple style sheet file with a name style.css having the following rules:

h1,  h2,  h3  {
        color: #000000;
        font-weight: normal;
        letter-spacing: 6em;
        margin-top: 3em;
        text=transform: uppercase;
}

Now you can include this file style.css into any HTML document as follows:





Imported CSS - @import Rule
@import is used to import an external stylesheet in a manner similar to the element. Here is the syntax of @import rule.





Here URL is the URL of the style sheet file having style rules. You can use another syntax as well:





Example
Following is the  example showing you how to import a syle sheet file into a HTML document:


@import  "style.css" ;


CSS Rules Overriding
We have discussed four ways to include style sheet rules in a HTML document. Below is the rule to override any Style Sheet Rule.
  • Any inline style sheet takes the highest priority. So, it will override any rule defined in tags or rules defined in any external style sheet file.
  • Any rule defined in tag will override the rules defined in any external style sheet file.
  • Any rule defined in the external style sheet file takes the lowest priority, and the rules defined in this file will be applied only when the above two rules are not applicable.

Handling Old Browsers 
There are still many old browsers who do not support CSS. So, we should take care while writing our Embedded CSS in a HTML document. The following example shows how to use comment tags to hide CSS from older browsers:







CSS Comments
Many at times, you may need to put additional comments in your style sheet blocks. So, it is very easy to comment any part in the style sheet. You can simply put your comments inside /*.... this is a comment in style sheet....*/.
You can use /* .....*/ to comment multi-line blocks in similar way you do in C and C++ programming languages.

Example

/* This is an external style sheet file */

h1,  h2,  h3  {
        color: #000000;
        font-weight: normal;
        letter-spacing: 6em;
        margin-top: 3em;
        text=transform: uppercase;
}

/* end of style rules. */

Alright guy! that's it for this tutorial on CSS inclusion, feel free to drop your questions on the comment box below. Don't forget to like our facebook page and to subscribe with us. See you in my next tutorial, bye for now.

Links to previous tutorials on CSS : Css Introduction (Css tutorial) ,  Syntax (Css tutorial)    


This post first appeared on Web Design Tutorialz, please read the originial post: here

Share the post

Inclusion (Css tutorial)

×

Subscribe to Web Design Tutorialz

Get updates delivered right to your inbox!

Thank you for your subscription

×