
19.2K
COCSS Nesting of Hover
The CSS nesting of hover is a technique used to apply styles to an element when it is hovered over, and also to its child elements.
Example
```
.parent {
background-color: #f2f2f2;
}
.parent:hover {
background-color: #ccc;
}
.parent:hover .child {
color: #fff;
}
```
In this example, when the `.parent` element is hovered over, its background color changes to `#ccc`, and the text color of its child element with the class `.child` changes to `#fff`.
Nested Hover Example
```
.parent {
background-color: #f2f2f2;
}
.parent:hover {
background-color: #ccc;
}
.parent:hover .child {
color: #fff;
}
.parent:hover .child:hover {
font-size: 18px;
}
```
In this example, when the `.parent` element is hovered over, its background color changes to `#ccc`, and the text color of its child element with the class `.child` changes to `#fff`. Additionally, when the `.child` element is hovered over, its font size changes to `18px`.
Sass Nested Hover Example
```
scss
.parent {
background-color: #f2f2f2;
&:hover {
background-color: #ccc;
.child {
color: #fff;
&:hover {
font-size: 18px;
}
}
}
}
```
In this example, the same styles are applied as in the previous example, but using Sass's nested syntax.
#programming
#coding
#webdevelopment
#css
#ezysnippet
@code_with_nadeem










![#Nesting Css Selectors Reel by @codewithvaishnavi - [read here ↴ ]
1️⃣ Excessive Repaints & Reflows - Updating DOM or styles too often? That's why smooth animations lag.
2️⃣ Heavy CSS Selectors - Comple](https://image.pictame.com/img/624147627_835796322771633_3262331831015194103_n.jpg?hash=aHR0cHM6Ly9zY29udGVudC1mcmE1LTIuY2RuaW5zdGFncmFtLmNvbS92L3Q1MS43MTg3OC0xNS82MjQxNDc2MjdfODM1Nzk2MzIyNzcxNjMzXzMyNjIzMzE4MzEwMTUxOTQxMDNfbi5qcGc/c3RwPWRzdC1qcGdfZTM1X3M2NDB4NjQwX3R0NiZfbmNfY2F0PTEwNiZjY2I9Ny01Jl9uY19zaWQ9MThkZTc0JmVmZz1leUpsWm1kZmRHRm5Jam9pUTB4SlVGTXVZbVZ6ZEY5cGJXRm5aVjkxY214blpXNHVRek1pZlElM0QlM0QmX25jX29oYz1jVUpQLWpBbmNkUVE3a052d0hZQUxDeCZfbmNfb2M9QWRvdmZZRVFBUGdmN1ExSFU1dFhON2FnbXRpVG5fNUdkVXJteGZNQ0szWk1sRDE4Ql9XMEpWdG9DLVY2bzZIT0hfZyZfbmNfenQ9MjMmX25jX2h0PXNjb250ZW50LWZyYTUtMi5jZG5pbnN0YWdyYW0uY29tJl9uY19naWQ9ZXdKSm15cy0xSHBLQWV2RU5YQXY3QSZfbmNfc3M9N2EzODkmb2g9MDBfQWYzS2NsNmJ2elpVZWM0ZnZOU3FSc01VNmRVUTdLV1F3ZDI4UnV6MS11TDNYQSZvZT02OURBRTc2OQ==)