Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Inheritance | Selecting and Targeting Elements
CSS Foundations

bookInheritance

When you apply CSS to an element, certain properties are automatically passed down to its child elements. This process is called inheritance. Inheritance helps you keep your stylesheets cleaner and more efficient, because you do not need to repeat common styles for every element.

index.html

index.html

style.css

style.css

copy

Not all CSS properties are inherited. Inheritable properties include those related to text and font, such as color, font-family, and font-size. These properties will be passed from a parent element to its children unless specifically overridden. For instance, if you set color on a parent <div>, all text inside that <div> will display in that color unless a child element has its own color rule.

Non-inheritable properties are usually those that affect the layout or the box model, such as border, margin, padding, and background-color. These properties apply only to the element you select, not to its children. In the example above, the border and background-color set on .parent do not affect the <p> or <span> elements inside it.

Understanding which properties inherit by default allows you to write CSS more efficiently and predict how your styles will cascade throughout your HTML structure.

question mark

Which CSS property is typically inherited by child elements?

Select the correct answer

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 2. Kapitel 7

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

Suggested prompts:

Can you give examples of how inheritance works in CSS?

Which CSS properties are inherited by default?

How can I override inherited styles for a specific element?

Awesome!

Completion rate improved to 6.67

bookInheritance

Svep för att visa menyn

When you apply CSS to an element, certain properties are automatically passed down to its child elements. This process is called inheritance. Inheritance helps you keep your stylesheets cleaner and more efficient, because you do not need to repeat common styles for every element.

index.html

index.html

style.css

style.css

copy

Not all CSS properties are inherited. Inheritable properties include those related to text and font, such as color, font-family, and font-size. These properties will be passed from a parent element to its children unless specifically overridden. For instance, if you set color on a parent <div>, all text inside that <div> will display in that color unless a child element has its own color rule.

Non-inheritable properties are usually those that affect the layout or the box model, such as border, margin, padding, and background-color. These properties apply only to the element you select, not to its children. In the example above, the border and background-color set on .parent do not affect the <p> or <span> elements inside it.

Understanding which properties inherit by default allows you to write CSS more efficiently and predict how your styles will cascade throughout your HTML structure.

question mark

Which CSS property is typically inherited by child elements?

Select the correct answer

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 2. Kapitel 7
some-alt