Dino Geek, try to help you

How to use inheritance in CSS?


Inheritance is a way in CSS in which styles get applied to a parent element and are then passed on to its child elements. Not all properties are inheritable, but those that are will take on the value of their parent by default.

It takes the following steps:

1. Identify your parent HTML element: This can be any HTML element such as body, div, section, or article that contains child elements inside of it.

```

This is an example of CSS inheritance

This is another example of CSS inheritance

```
2. Define your CSS rules: In your CSS file or within your style tags if they are in your HTML documents you can define rules for your parent element. These styles will be inherited by all child elements.

```css #parent { color: blue; font-size: 20px; }
```
In this case, all child elements inside the div with the id of “parent” will inherit the color and font size. In other words, the text inside those child elements will be in blue color and of 20px size.

1. Overriding Inherited Styles: If you want a specific child element not to inherit any style from the parent, you can do so by specifying separate style for that child.

``` .child { color: red; font-size: 15px; }
```
Now, the child elements with the class “child” will not inherit color and font-size from the parent. Instead, they will have their own color (red) and font-size (15px).

Note: Not all CSS properties are inheritable, for example: padding, border, margin, etc. are not inherited from parent and they need to be specified directly for a child if you want to have them.


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use