In addition to, there's a way to let css inherit styles?

118 0

In some cases, css inherits the style of the parent element. How can you clear the inherited styles, them.

1 Answers

88 3

You can now clear the style only by override.
This problem should be taken into account when writing css
Generally only the style of, and the modules are suitable for use with inheritance.
Otherwise, it shouldn't be possible to inherit the style, and for two modules that differ in structure or performance, it isn't suitable for inheritance.
The best way to do this is to draw out the same , which isn't easy to change, then apply the to different modules.
Like two div.
<div class="a"></div>
<div class="b"></div>
A common style can be extracted and placed under a declaration:
.fixedAd {position:fixed;width:200px;height:200px;border:1px solid #ccc;}
Then write your own style for different div:
. A {color:#ffc;background:#ccf;}.
. B {color:#777;background:#999;}.
The last combined html structure is:
<div class="a fixedAd"></div>
<div class="b fixedAd"></div>
In short, the combination of is better than that of inheritance, which is the same as that of programming.