CLASS and ID

What does a CLASS refer to ?? Yeah, you are right. It refers to a group of people with common interest. Its same as the class in our schools and colleges. So , in the same way in CSS , class is defined as a group of elements on the webpage each having something common among them. Here the desired thing is their style (CSS). Suppose, we have to show list of friends you have in youe social network site. Now each of the friend has to be shown with same same style and design. So, in order to impement a unique style for all of them, we provide all of them same class and assign the style to that class. So, at once we are able to style a number of equivalent things. Lets see an example.

		
		
		

This is some text in para 1

This is some text in para 2

This is some text in para 3

This is some text in para 4

This is some text in para 5

So, now we can apply same style to whole lots of things on our webpage within few lines. Moreover, we are selective now. We are not applying to everything on the document.

ID

Every company or college gives ID card to its students, so that it can distinguish any two. This ID is unique to him. Same is the case here also. If we wish to apply a CSS to only a particular element on the document. We can assign an ID to that element (tag) and set its style. Remember, this is more preferable than inline CSS , even if you need to write one style for one element. This is because, it can then be transferred within pages.

Silly point to note is that if you assign same ID to more than one element, it will not apply design to any of them or apply design to only one of them(first one) depending upon the browser. So, be cautious while distributing Ids to the tags. Here is an example

		
		
		

I have special powers \m/

This is some text in para 2

This is some text in para 3

This is some text in para 4

This is some text in para 5

Yipee !! , now we have learnt how to apply a basic CSS to selected element on our webpage. Lets learn how to write more efficient style because efficiency matters.

Member Login

Member Login




Not a Member? Sign Up!




Login to comment

Be the first to comment on this topic







  


<<< Wanna review

Continue >>>