So, I am a bit confused over this simple thing, i've googled as much as i could, but i just dont know the right keywords for googling it, i tried CSS selectors, etc, no answer was enough to clear my confusion. So i've also tested and p.classname doesn't even seem to work, but by definition in a book i'm reading ( updated 2012 )
To create a class in CSS and select an element in that class, you write a class selector, like this:
p.classname{ stuff }
So now you have a way of selecting
elements that belong to a certain class to style them.
I couldn't find a definition for
classname p
, but myself would give something like this definition "select all p elements that belong to classname", which is basicly the same.
the p.classname
works when i give the "classname" to a im still confused, at the moment i would suppose im just going to perma use the .classname p, which works and is basically the same.
So, please help me out to clear this confusion, i've googled, i tried to help this confusion but it didn't work, it only made more.
Thanks
CSS works by reading each rule in order, example.
Same goes for classes
So in your example defining a
class
first will target each and every element that has that class.By defining something after that class
.class p
it will target all elements inside that class which are p.Hope this helped
UPDATE
so you can understand better,
It works exactly the same for classes as it does with elements.
So when you do
You are looking for a
<p>
with classclassname
when you do
You are looking for a
p
that is a descendant of the classesclassname
.In CSS
.
is used as a selector for a class name.