tags:

views:

191

answers:

3

i have something like this

 <body>
    <h2>
    Blue 
    <span>
    <a ....>add to combo</a>
    </span>
    </h2>
  </body>

and css

#body {font-size: 100%}
h2{font-size: 200%}
a{font-size: 80%}

now ive been reading up and realise that the link a wont be 80% of 100% but rather 80% of 200% of 100% because percentages are taken from parents size.

However Id like all my font-size declarations in percentages to not inherit, but rather to just calculate from some site wide base font-size say 16px?

How do you do that?

A: 

Try to use "!important" rule:

http://www.w3.org/TR/CSS2/cascade.html#important-rules

Roberto Aloi
Wouldn't that cascade in the same way as explained in the question, unless an explicit `font-size` was given?
David Thomas
I would also suggest you to use a tool like "Firebug" to live edit/view your CSS properties to play with them. One of the nice features of this tool is that it will show you exactly which properties are evaluated and which are overridden, and why.
Roberto Aloi
if you use the important rule editing will be harder in time. Try to figure out how the "cascading" rules work in css. http://www.w3.org/TR/CSS2/cascade.html#specificity
Robert Cabri
A: 

I don't think you can override inheritance, since that's part of the cascade of Cascading Style-Sheets.

For your usage you'll either have to explicitly state the font-size (this is likely to get very tedious and error-prone very quickly) for elements using (very) specific selectors, eg:

h2 span a {font-size: 18px; } /* or whatever */

Or reorder your html so that the span is a sibling of the h2, rather than descendant. I agree that it should be possible, though.

David Thomas
A: 

What you want is not possible with your give code. You want to inherit font 1 particular size, then every font-size in childNodes will be relative to the parent.

if you want to use certain font sizes and not inherit you should explicitly set them

That said never try to use the important statement. Please checkout how CSS assigns his properties to HTML nodes

http://www.w3.org/TR/CSS2/cascade.html#specificity

Robert Cabri
But i thought explicity setting font sizes wasnt good because that doesnt give the user the power to set the size they want via there browser. What i want is to be able to set my font sizes but if the user changes the font size via the browswer they can but my text will still be in proportion.
adam
if you want to specify font sizes proportional use the "em" unit for fonts.
Robert Cabri