+ 1
Can someone explain Inheritance in html and css?
Can someone explain Inheritance in html and css?
2 odpowiedzi
+ 10
Inheritance in HTML and CSS is when child elements automatically adopt styles from their parent elements.
Imagine you have a simple HTML structure:
<div class="parent">
<p>This is a paragraph in the parent.</p>
<div class="child">
<p>This is a paragraph in the child.</p>
</div>
</div>
With the following CSS:
.parent {
color: blue; /* Text color for the parent */
font-family: Arial; /* Font for the parent */
}
.child {
color: red; /* Text color for the child, overriding the parent's color */
}
What happens?•The text in the <p> inside .parent will be blue because it inherits the color.•The text in the <p> inside .child will be red because it explicitly sets its own color, overriding the inherited blue color from its parent.
+ 2
Oh thanks