Forum Moderators: not2easy
Here is the DIV:
<div class="InteriorText">
<p>When it comes to technology, have you ever noticed that there is always something that someone doesn't want you to buy?</p></div>
Here is the DIV's CSS:
.InteriorText p{
color: #666666;
font-family: Arial, Helvetica, sans-serif;
font-size: 0.8em;
}
Here is the class I would like to apply to certain P tags within the same DIV, but is being "overridden" by the above CSS:
.ContentSubHead {
font-size: 2.0em;
font-weight: bold;
}
And finally, the HTML code snippet:
<div class="InteriorText">
<p class="_ContentSubHead">When it comes to technology, have you ever noticed that there is always something that someone doesn't want you to buy? </p></div>
Any help would be greatly appreciated... Thanks!
<p class="_ContentSubHead">
When you name your styles you need to start with a letter. In your (x)html code you have the underscore, which is not only incorrect, but it could be a typo as your class name doesn't have the _ in front of it.
4~css
IE doesn't like font-size: ...em either. Try font-size: 80%. IE likes percents.
I use font sizes in ems all the time. I have never had any difficulty with them.
What I do is put in the html body {font-size: 100.01%} along with a few other things I always put there, and then my font sizes I do with ems. This way when people resize their fonts to see a larger font, they size perfectly for me.
Can you explain your statement as to why IE doesn't like it I would appreciate it.
I can't explain it. Only the IE developers could do that. I've just found that, by extensive testing, under some circumstances IE screws up font size if it is specified in 'em'. In my CSS initialization (setup.css), I have this:
body{cursor:default;line-height:1.2em}
body *{cursor:inherit;font-size:100%;line-height:1.2em}
a{cursor:pointer}
I have found that including that initialization and then specifying all descendant font-size in percent always works. If I desire different body font size, I use the cascade to overload the initial value above.
Once you have the initial percentage value (I generally uses about 90% on the body element too) in there IE will resize the ems properly.
re the opening question, after you've got your class name sorted out (take out that underscore) I think you have a specificity issue?
.InteriorText p {}
is more specific than .ContentSubHead {}
and will overrule it no matter which order in the cascade they come
try
p.ContentSubHead {}
though it will need to be later in the cascade as that then gives it the same specificity as the first rule
or even
.InteriorText p.ContentSubHead {}
which is more specific than the first rule and follows the logic anyway
I'm sure we see just a sample but there is little need to have a <div> wrapping a single <p>
- you can style the <p> just as well
- you can also apply multiple classes onto one element
so
.red {color:red}
.widget {font-weight:bold}
both should be applied to <p class="red widget">test</p>
using them encapsulating single other leements can be sueful as CSS only has one margin, border and padding. If you need more than one (e.g. to get a rainbow border, you'll need a few more)