How select works

can someone please explain how selecting a class in CSS works because sometimes we use “.” before the class sometimes"#" and other times nothing at all just the class
please how do you know which to use.

yup good question.

All HTML can be selected in the CSS by just writing their name like this:

input {
}

So up there I’m trying to select all input tags in general.

Then there are elements that have an attribute called ‘class’, which you may recall.
It’s like in school, when you go to a classroom, you are a member of that class.
And if you put some elements, even very different elements in the same class by giving them the same class attribute value, then you can select them all like this:

.grade1 {
}

… where all elements whose class attribute is equal to grade1 will be selected.

Another selector (and there are many many of them) is the one that selects by the id attribute.
Sometimes elements are just unique. You want them to be treated in a special way.
So you give them an id attribute (that is unique) and to select that specific element with that specific id you say:

#special {
}

where the element selected here will have id=“special”.

Hope this helps. And feel free to google as there are many many more selectors out there.

thanks this helps alot
in a case of picking a general element you use just the name
when its a class it has a “.” before the name
when it’s an id, we use “#” if i’m right

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