1. Styles can be inherited from a parent
Some styles, like font family, text-alignment etc., are automatically inherited by child elements from their parent element (i.e. by an element contained inside another one).Others are not automatically inherited.
Example
<div style=”font-family:serif; border:1px solid red; padding:10px;”>
However, you can make an element inherit styles from its parent.This text will be in a serif font.
<p>
This text is also in a serif font, because font is inherited by default.
But the border and padding properties are not inherited from the parent div.
</p>
</div><p>
This text is also in a serif font, because font is inherited by default.
But the border and padding properties are not inherited from the parent div.
</p>
Example
<div style=”font-family:serif; border:1px solid red; padding:10px;”>
This text will be in a serif font.
<p style=”border:inherit;”>
</div><p style=”border:inherit;”>
Now the paragraph also has a red border.
Border properties are not inherited by children, by default, but because I set border to “inherit”, it is.
</p>Border properties are not inherited by children, by default, but because I set border to “inherit”, it is.
No comments:
Post a Comment