I do not quite understand what is happening:
Using the universal selector * reset the parameters, including font-size: 0; , then in the markup for the header block, set the font size, for example, 16px. There are several headers in this block, and as I understand it, they must inherit the font size of the parent ... but in fact it turns out to be 0.
Question: When using * , in this case, each tag needs to set the font size, since the property will not be inherited from the parent, but taken according to the rule "for all tags" and for redefinition it is necessary to set the property explicitly to each element?

  • Sorry. In general, I almost did not understand anything :) Do you have a problem that * has more priority than a class? - Telion
  • No, not in this. Using * reset the font size, then for a block with some content, set the size, but the tags inside the block do not inherit this rule and have to set it explicitly to tags directly - pepel_xD
  • Did you specify a font-size: inherit to inherit? You can do something like div * {font-size: inherit;} - Telion
  • You did not understand me, the font size is inherited by default, the meaning of writing inherit, in this case, it is not a problem to explicitly indicate it .... I just wanted to know how this behavior works, using the example of a universal selector and font size (the rule that is inherited) is pepel_xD

1 answer 1

For the selector * becomes more important than the standard value. To indicate that internal tags should follow the parent size, you need to exceed the asterisk priority. For example:

CSS

 * {font-size: 10px;} .txt {font-size: 20px;} .txt * {font-size: inherit;} 

HTML

 текст вне <div class="txt"> текст 0 <span>текст 1</span> <strong>текст 2</strong> <div>текст 3</div> </div> 

Displays internal content of 20px in size as indicated in the txt class and everything will be inherited, and this example:

CSS

 * {font-size: 10px;} .txt {font-size: 20px;} 

HTML

 текст вне <div class="txt"> текст 0 <span>текст 1</span> <strong>текст 2</strong> <div>текст 3</div> </div> 

Displays all 10px text as specified in the selector *.

  • font-size: 10; - can so font-size: 10px? - soledar10
  • @ soledar10 works in any version. But yes, it was implied after all 10px. - Telion
  • If you checked without a doctype, then yes, the browser will calculate in px, and if with a doctype, there will be an error invalid property value - soledar10
  • @ soledar10 true, it was a sampler even without <html> - Telion