Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize nesting in css

Shulou Source: shulou.com Published: 2022-06-01 05:15:35 09月21日 Update

This article mainly shows you "how to achieve nesting in css", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn how to achieve nesting in css "this article.

Nested 1. Basic concept

If you are familiar with Sass, you will know the convenience of nested selectors. Essentially, it is to write child rules in the parent. Nesting makes it easier to write CSS code, and now nesting has finally come to native CSS!

two。 Usage

Syntactically, it is similar to Sass. Let's define style rules for the h3 child elements in card for class:

.card {color: red; & h3 {color: blue;}}

You can use it for pseudo-classes and pseudo-elements:

.link {color: red; &: hover, &: focus {color: blue;}}

These are equivalent to the following CSS code:

.link {color: red;} .link: hover,.link:focus {color: blue;} 3. Current state

Currently, no browsers support nesting. If you use PostCSS, you can try nesting through the preset postcss-preset-env plugin.

These are all the contents of the article "how to achieve nesting in css". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Content articles code elements rules learning help similarity usage convenience can make can pass that is plug-ins methods easy to understand more essence organization style Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB OPPO Reno Linux Microsoft Shulou Technology