Https://www.codecademy.com/courses/learn-html-css/lessons/ids-classes-divs/exercises/html-classes?action=lesson_resume


#1

https://www.codecademy.com/courses/learn-html-css/lessons/ids-classes-divs/exercises/html-classes?action=lesson_resume
i don't understand the classes and id.


#2

What do you not understand? Is there something specific or just classes and id in general?


#3

i want to understand only classes and id. i don't know how to create class. and how can we give a name to class.


#4

So firstly this is a CSS class syntax.

.class {
    css declarations;
}

Here is a example. With this css class:

.main {
    background-color: yellow;
}

All elements with class="main" will have a background color of yellow. Class is used if you want to style lots of elements. ID is used when you want to style a specific element.

Here is ID syntax

#firstname { 
    background-color: yellow;
}

As you have most likely realised, all elements with id="firstname" will have a background color of yellow.
The biggest difference between class and id is the full stop and the hashtag. A full stop defines a class and a hashtag defines a ID.

I hope this has cleared it up, let me know if you need further explanation.


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.