+ 1
Hi guys. Anybody knows what will happen if we have more than 1 css code for an element?
In some cases an element matches more than one css property. For example an element has a class an also an id, so which one applies? Is there any link to find out the priorities in these cases?
9 Answers
+ 2
Paul Grasser yes id is always stronger than classes and tags' names .. if he uses id then the value that is given for id will be applied but if he uses tag's name or a class then the last given value will be applied.
+ 2
The last written code will be applied
forexample
p{
color: red;
}
.
.
.
.
p {
color: gray;
}
the font of all p tags will be gray because it is the last specified value.
Ä°n other words
The last given value will be overwritten the earlier given values
+ 2
Safaa Alnabhan not quite true even if you have id before and then something else the id is still the one applied
+ 2
You don't need a reference to learn things like these .. You need to have a practice .. you should try and write the code in your text editor and see what happened .. then you can ask here about your wondering issues to be sure about the result you got it .. things like this you learned it by time and by trying listening to others reading and working on many projects âș
Google is your best friendđ
+ 1
What happen if they have conflicts? For example :
#id{color:yellow;}
.class{color:blue;}
0
They are both applied, if that's what you mean.
0
The id is used.
0
Do you guys know any reference?
0
For another conflicts I mean?