Forums: Front End:

 

defining p tag in class

first
 

ernieweaselfat defining p tag in class

Am I going crazy... why doesn't this work?

I've got an ID and a Class as follows


#myId
{
width:500px;
height:500px;
}

#myID p
{
font-size:1em;
}

.myClass
{
width:100px;
height:100px;
}

.myClass p
{
font-size:0.8em;
}


And my document is like this:

<div id="myId">
<p>My ID text</p>
<div class="myClass">
<p>My CLASS text</p>
</div>
</div>


The result is that both "my CLASS text" and "my ID text" come out at 1em. Why doesn't the ".myClass p" statement overwrite the "myID p"??

 

DontBogartMe

try this:

#myId .myClass p

{

font-size:0.8em;

}


I think it's because in CSS rules an ID is given higher importance than a class - therefore the ID rule overrides the class rule

"anything invented before you were 18 has been there forever, anything that turns up before you're 30 is new and exciting, and anything after that is a threat to the world and must be destroyed."

quote
 

ernieweaselfat

aha, worked like a charm

Thanks (as usual) DBM!

 

JERKSTORE

An ID will override a class. So all the p tags in your code were giving priority to the ID and ignoring the class within that ID.

So if you want a class within an already defined ID to override that ID, you have to point to it specifically as a child of the ID, like DontBogartMe did in his example.

Which I guess is what Bogey already said wink

 

DontBogartMe

well, it's nice to be backed up anyway big grin

"anything invented before you were 18 has been there forever, anything that turns up before you're 30 is new and exciting, and anything after that is a threat to the world and must be destroyed."

quote
 
first
 

Forums: Front End: defining p tag in class

 
New Post
 
You must be logged in to post