There is such code:
<div class="div1"> <div class="div11">Текст</div> </div> <div class="div2"> <div class="div12">Текст</div> </div> How to make it so that when you hover on .div11, the background of div12 changes. Layout can not be changed.
There is such code:
<div class="div1"> <div class="div11">Текст</div> </div> <div class="div2"> <div class="div12">Текст</div> </div> How to make it so that when you hover on .div11, the background of div12 changes. Layout can not be changed.
var div11 = document.querySelector('.div11'); var div12 = document.querySelector('.div12'); div11.addEventListener('mouseover', handle); div11.addEventListener('mouseleave', handle2); function handle() { div12.style.background = 'lightgreen'; } function handle2() { div12.style.background = ''; } <div class="div1"> <div class="div11">Текст</div> </div> <div class="div2"> <div class="div12">Текст</div> </div> No, if you use only CSS - CSS rules are cascading. It is possible only through the guidance on .div1 , because It is on par with .div2 .
If through the use of scripts, for example, like this:
$('.div11').hover( function() { $('.div12').css('background', 'green') }, function() { $('.div12').css('background', 'transparent') } ) <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script> <div class="div1"> <div class="div11">Текст</div> </div> <div class="div2"> <div class="div12">Текст</div> </div> Even if there are more lines (and without JavaScript):
div[class^="div"]:hover + div[class^="div"] > div { background: lime; } <div class="div1"> <div class="div11">Текст</div> </div> <div class="div2"> <div class="div12">Текст</div> </div> <div class="div3"> <div class="div13">Текст</div> </div> <div class="div4"> <div class="div14">Текст</div> </div> <div class="div5"> <div class="div15">Текст</div> </div> <div class="div6"> <div class="div16">Текст</div> </div> div that is colored, and in the second case, the class of parents is changed. - lexxl<div class="div1"> ? the ban on changing the markup means, most likely, that this is already a working project, and changes may entail a series of other undesirable rework. and the classes are given in the example, for sure, conditionally - lexxl.div1:hover~.div2 .div12 { background: tomato; } .div1:hover~.div2 .div12 { background: tomato; } , BUT NOT SO (this code will not work): .div11:hover~.div2 .div12 { background: tomato; } .div11:hover~.div2 .div12 { background: tomato; } - HamSterSource: https://ru.stackoverflow.com/questions/585808/
All Articles
css/js/ ...? specifying only thehtmltag in the question does not make it clear. - lexxl