+ 1

Can someone explain Inheritance in html and css?

Can someone explain Inheritance in html and css?

9th May 2025, 7:42 PM
Anne
Anne - avatar
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.
9th May 2025, 8:22 PM
Fatema Abdullah
Fatema Abdullah - avatar
+ 2
Oh thanks
9th May 2025, 8:35 PM
Anne
Anne - avatar