When using CSS pseudo-elements to control elements, you often need to change the styles of some elements. There are many blogs on the Internet that talk about how to control the change of one element, but in the actual writing process, I found that more often I need to control the changes of multiple consecutive elements. Use pseudo elements to control (take :hover as an example). When the mouse stays on A, the styles of BCD... change. A and BCD....are adjacent and of the same level, requiring A to be at the top of BCD <div class="A"></div> <div class="B"></div> <div class="C"></div> <div class="D"></div> //The corresponding CSS code of A controlling BCD. A:hover + .B{ background-color: orange; } .A:hover + .B+ .C{ background-color: orange; } .A:hover + .B+ .C+ .D{ background-color: orange; } If you move A to another position, the effect will not be achieved; or if you only write the control code at the bottom of the CSS, you can only control the style change of the third element, and multiple elements cannot be changed together. A is BCD....is a father-son relationship <div class="A"> <div class="B"></div> <div class="C"></div> <div class="D"></div> </div> //Corresponding CSS code.A:hover .B{ background-color: orange; } .A:hover .B+ .C{ background-color: orange; } .A:hover .B+ .C+ .D{ background-color: orange; } The first one is actually very easy to understand, because element+element is to control adjacent elements. Since A and CD are not directly adjacent, I will search one level at a time, first to B, because BC are adjacent, so I can start to control it, and the same goes for D. In the second code, element element is the method by which the parent node controls the child node. A can directly control B. If you need to control C, then find B first. Since BC are adjacent, I will use the method of adjacent element control to control C. The same goes for D. This concludes this article on how to use CSS pseudo-elements to control the styles of several consecutive elements. For more information about CSS pseudo-elements controlling elements, please search previous articles on 123WORDPRESS.COM or continue browsing the related articles below. I hope you will support 123WORDPRESS.COM in the future! |
<<: Two methods to disable form controls in HTML: readonly and disabled
>>: Vue Basics Listener Detailed Explanation
The methods and concepts of private filters and g...
Table of contents Preface What to use if not jQue...
Mainly discuss its structure and some important pr...
Vue routing this.route.push jump page does not re...
If you want the path following the domain name to...
This article uses examples to describe the add, d...
This article shares with you the graphic tutorial...
<META http-equiv="Page-Enter" CONTENT...
This article example shares the specific code for...
Table of contents Business Background Using Techn...
Sometimes it’s nice to see some nice scroll bar e...
1. Do a good job of cleaning before installation ...
Table of contents 1. Environment Configuration 1....
<br />Original source: http://www.a-xuan.cn/...
Directory Structure . │ .env │ docker-compose.yml...