Overriding properties in CSS
Because id+selector (#iddiv span) is more specific than a class. Either
#iddiv span.myclass
or
#iddiv .myclass
should work for this case.
Learn more about CSS specificity here or by Googling it.
CSS class override property behaviour
It's the latter. Cascade resolution is on a per-property basis. If the color
property exists somewhere with higher precedence (in this case, the internal stylesheet), then that property is cascaded to the more precedent one. The rest of the properties carry over because no more precedent declarations exist.
Interestingly, the CSS2.1 spec seems to conflate "style rules" and style declarations, in section 6.4. This may be a source of confusion. The subsection 6.4.1 clarifies this by referring only to property declarations.
Overriding CSS properties for a specific html element
That's a CSS specificity issue.
.main_section article
has a higher specificity value than .special-bg
selector.
In terms of value:Inline Style
> IDs
> Classes, Attributes, and Pseudo-classes
> Element Types and Pseudo-elements
, So the calculation of Specificity of these two CSS selectors would be:
.special-bg
Inline Style ID (Pseudo-)Class (Pseudo-)Element
0 0 1 0
.main_section article
Inline Style ID (Pseudo-)Class (Pseudo-)Element
0 0 1 1
11
> 10
=> .main_section article
selector wins!
You could use the following:
.main_section .special-bg {
/* Styles goes here... */
}
Further reading:
- http://coding.smashingmagazine.com/2007/07/27/css-specificity-things-you-should-know/
- http://reference.sitepoint.com/css/specificity
- http://cssspecificity.com/
And a great tool to calculate the specificity value:
- http://specificity.keegan.st/
Overriding CSS property all: unset
It does not appear to be possible to undo the effects of the all
property once it has been specified. This may be due to all
being a shorthand property (that happens to accept only the CSS-wide keywords as values).
You can't erase a shorthand declaration from the cascade the same way that css-cascade-4's introduction of the revert
keyword allows you to erase author-level declarations, and that's because a shorthand property doesn't exist as its own entity in the cascade; instead, it simply represents all of its component properties. Like with the more traditional shorthand properties such as background
and font
, the only way to override a shorthand declaration that has been applied is to re-specify the values for the longhands that were overridden, either via longhand declarations or via another shorthand declaration. But you can't do the latter with the all
property since it only accepts CSS-wide keywords.
As the former is obviously not practical with the all
shorthand, since you can't predict which author-level declarations are being overridden to begin with, your only other option is to restrict it via a selector, thereby preventing it from ever applying in specific circumstances in the first place. Hopefully we will see more implementations of level 4 :not()
in the near future, which will make writing selectors a little easier.
Can I reset a CSS property rather than overriding it?
To answer your question (rather than solving your problem)...
Can I reset a CSS property rather than overriding it?
Reset to what?
The C in CSS stands for cascading and you'll always have several layers of styles combining among themselves with precisely defined though not always immediately clear rules. Apart from the styles set by the site author in different places (external CSS files, <style>
blocks, style=""
attributes...), in the base line we'll find the builtin browser styles and as far as I know browser vendors are free to assign whatever default styles they choose—and often users can add their own styles to the soup, either with builtin settings or with add-ons. Even the so called CSS resets don't actually reset anything. They merely add yet another layer of styles on top of the rest.
There's no syntax for "Create a snapshot here" (which would be the only solution I can think of without a thorough analysis) so the answer is basically no.
Related Topics
Javafx: Styling Application with CSS Selectors
How to Change Font-Size of a Tag Using Inline CSS
How to Audit Multiple Pages with Chrome Developer Tools
Font Awesome Icons Not Working in Osx Safari
CSS Selector Wildcard Inside Class Name
Em Vs Px and Cross Browser Compatibility
CSS Firefox - How to Deactivate The Dotted Border ( Firefox Click Indicator )
Force Nested Divs to Have Min-Height of 100%
How Necessary Are CSS3 Vendor Prefixes Right Now
Change CSS Variables Dynamically in Angular
I Am Gettiing an Error Expected New Line While Compiling Sass
Table Overflows Parent Div When Td Content Is Too Wide
Animating Elements Sequentially in Pure CSS3 on Loop
CSS Sprite Techniques, CSS Background or Img's Clip
How to Make Bootstrap Readonly Input Field Look Like Normal Text
How to Prevent CSS Declaration Dropped Errors Cross Browser
Explain Regex That Finds CSS Comments
CSS: Why Is Vertical-Align: Baseline Stop Working on Firefox When Using Overflow: Hidden