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

@ Rules (Css tutorial)

Hello guys! evening and welcome to a brand new episode  of my tutorial on CSS. I know you guys are not really happy that i don't update my tutorial posts regularly, i apologise.

In my last tutorial post on CSS i talked about Pseudo elements which i explained in details the various Pseudo elements and their applications. Now in this tutorial post i want to talk about the @ Rules  and their applications.

This tutorial will cover the following important @ rules:

  • The @import: rule imports another style sheet into the current style sheet.


  • The @charset: rule indicates the character set the style sheet uses.
  • The @font-face: rule is used to describe a font face for use in a document.
  • The !important rule indicates that a user-defined rule should take precedence over the author's style sheets. 
Note: There are other @ rules which i will cover in subsequent chapters.

You can also read: Positioning (Css tutorial) 

The @import Rule
The @import rule allows you to import styles from another style sheets. It should appear right at the start of the style sheet before any of the rules, and its value is a url.

It can be written in one of the two ways below:


The importance of @import rule is that it allows you to develop your style sheets with a modular approach. You can create various style sheets and then include them wherever you need them.

You can also read: Visibility (Css tutorial)

The @charset Rule
If you are writing your document using a character set than ASCII or ISO-8859-1 you might want to set the @charset rule at the top of your style sheet to indicate what character set the style sheet in written in.

The @charset rule must be written right at the beginning of the style sheet without even a space before it. The value is held in quotes and should be one of the standard character-sets. 

The below example shows how we can write the @charset rule in two ways:


The @font-face Rule
The @font-face rule is used to describe a font face for use in a document. @font-face may be used to define a location of a font for download, although this may run into implementation-specific limits.

In general , @font-face is extremely complicated, and its use is not recommended for any except those who are experts in font matrics.

Below is a short example:


You can also read: Css List (Css tutorial)

The !important Rule
Cascading style sheets cascade. This means that the styles are applied in order as they are read by the browser. The first style is applied and then the second and so on.

The !important rule is a way to make your CSS cascade but also have the rules you feel are most crucial always be applied. A rule that has the !important property will always be applied no matter where the rule appears in the CSS document.

For example in the following style sheet below, the paragraph text will be black, even though the first style property is applied red:


So if you want to make sure a property always applied, you would add the !important property to the tag. So, to make the paragraph text always red, you should write it as follows:


Here you have made P { color: #ff0000  !important; } mandatory, now this rule will always apply even though you have defined another rule p { color: #000000; }.

Alright guys we have come to the end of this tutorial, feel free to ask your question in areas that you don't understand very well. Don't forget to like our facebook page and also follow us on google + and finally subscribe with us to get our tutorial posts delivered directly to your emails.

See you guys in my next tutorial, bye for now.


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

Share the post

@ Rules (Css tutorial)

×

Subscribe to Web Design Tutorialz

Get updates delivered right to your inbox!

Thank you for your subscription

×