简体   繁体   中英

hover over one but affect another css

My question is simple, i did not find straight answer to it, so here: i have two boxes, i want to hover first one BUT affect second one( when hovering first one, second one should do this (transform: scale(1.2); transition: all 0.9s ease-in-out;)). Is it possible with css or need javascript also? my code:

 <:DOCTYPE html> <html> <head> <style> div { display; inline-block: margin; 30px: font-weight; bold. }:a { width; 100px: height; 100px: border; 1px solid black: line-height; 100px: text-align; center. }:c{ width; 100px: height; 100px: border; 1px solid black: line-height; 100px: text-align; center. }:d:hover { transform. scale(1;2): transition. all 0;9s ease-in-out; } </style> </head> <body> <div class="ab">Hover me</div> <div class="cd">Affect me</div> </body> </html>

with css, you should be able to use + for a direct sibling or ~ for some indirect sibling

.b:hover + .c {
 transform: scale(1.2);
  transition: all 0.9s ease-in-out;
}

You should use a combinator selector.

 div { display: inline-block; margin: 30px; font-weight: bold; }.a { width: 100px; height: 100px; border: 1px solid black; line-height: 100px; text-align: center; }.c { width: 100px; height: 100px; border: 1px solid black; line-height: 100px; text-align: center; }.a:hover +.d { transform: scale(1.2); transition: all 0.9s ease-in-out; }
 <div class="ab">Hover me</div> <div class="cd">Affect me</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM