Hi guys. Anybody knows what will happen if we have more than 1 css code for an element? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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?

16th Aug 2019, 5:35 AM
MohammadReza Esmaeili
MohammadReza Esmaeili - avatar
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.
16th Aug 2019, 6:40 AM
Safaa Alnabhan
Safaa Alnabhan - avatar
+ 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
16th Aug 2019, 6:31 AM
Safaa Alnabhan
Safaa Alnabhan - avatar
+ 2
Safaa Alnabhan not quite true even if you have id before and then something else the id is still the one applied
16th Aug 2019, 6:32 AM
Paul Grasser
Paul Grasser - avatar
+ 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👍
16th Aug 2019, 7:28 AM
Safaa Alnabhan
Safaa Alnabhan - avatar
+ 1
What happen if they have conflicts? For example : #id{color:yellow;} .class{color:blue;}
16th Aug 2019, 5:50 AM
MohammadReza Esmaeili
MohammadReza Esmaeili - avatar
0
They are both applied, if that's what you mean.
16th Aug 2019, 5:47 AM
Paul Grasser
Paul Grasser - avatar
0
The id is used.
16th Aug 2019, 5:52 AM
Paul Grasser
Paul Grasser - avatar
0
Do you guys know any reference?
16th Aug 2019, 7:22 AM
MohammadReza Esmaeili
MohammadReza Esmaeili - avatar
0
For another conflicts I mean?
16th Aug 2019, 7:23 AM
MohammadReza Esmaeili
MohammadReza Esmaeili - avatar