Problem
1: .root .main
is not a sibling of .root .menu li
.
2: There isn't a CSS selector currently capable of doing what you're trying to do - See the MDN docs. You will need to use a bit javascript/jQuery. Here are a few possible solutions...
Solution 1: Classes
CSS:
/* Default styling */
.menu {
background: green;
color: blue;
}
/* Hovered styling */
.menu.hovered {
background: purple;
color: red;
}
jQuery:
$('.root .menu li').hover(function() {
$('.root .main').addClass('hovered');
}, function() {
$('.root .main').removeClass('hovered');
});
Solution 2: Inline styling
CSS:
/* Default styling */
.menu {
background: green;
color: blue;
}
jQuery:
$('.root .menu li').hover(function() {
$('.root .main').css('background', 'purple');
$('.root .main').css('color', 'red');
}, function() {
$('.root .main').attr('style', '');
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…