Inheritance in CSS

Inheritance in CSS ka matlab hai ki agar kisi element par koi property define nahi ki gayi hai, to wo ya to apne parent element se value le lega, ya phir apni default (initial) value use karega.

Inheritance in CSS me properties do types ki hoti hain:

  • Inherited properties
  • Non-inherited properties

Inherited Properties

Inherited properties by default parent element ki value ko follow karti hain.

Text related properties jaise color, font-family, font-size, line-height, aur text-align usually inherit hoti hain. Isse pure document me consistent styling maintain hoti hai.

Example

Inheritance in CSS

Yaha <strong> element automatically parent (<p>) se color aur font-size inherit karega.


Non-inherited Properties

Agar non-inherited property ki value set nahi hoti, to wo apni default (initial) value le leti hai.

Box model aur layout related properties jaise border, background, margin, padding, width, aur height usually inherit nahi hoti.

Example

Non-inherited Properties

Yaha <strong> element par border apply nahi hoga, kyunki border inherit nahi hota.


Inheritance in CSS (The inherit Keyword)

inherit keyword ka use explicitly inheritance apply karne ke liye hota hai.

Ye inherited aur non-inherited dono properties par kaam karta hai.

Example

The inherit Keyword

Yaha <strong> element parent (<p>) se border inherit karega kyunki humne inherit keyword use kiya hai.


Inheritance in CSS me child elements parent ki properties le sakte hain. Text properties usually inherit hoti hain, jabki layout properties nahi hoti.

Leave a Comment