What is inheritance in CSS?
Some CSS properties are inherited: a child element gets the value of its parent if you do not set one. Text properties like color, font-family, font-size and line-height are inherited. Box properties like margin, padding and border are not.
body { color: #333; font-family: Arial, sans-serif; } /* all text inside inherits it */
.box { border: 1px solid red; } /* the children do not get the border */
.child { border: inherit; } /* force inheritance */
See CSS Specificity.
Learn more about the similar topics:
| Tutorials |
|---|
| CSS Selectors |
| CSS Specificity |
| CSS Pseudo-classes and Pseudo-elements |
| Exercises & Assignments |
|---|
| No Content Found. |