<div class="test1"></div> <div class="test3"></div> <div class="test3"></div> How test 3 on test 1 affect? with hover? no + no ~ does not help
<div class="test1"></div> <div class="test3"></div> <div class="test3"></div> How test 3 on test 1 affect? with hover? no + no ~ does not help
Well, depending on the structure, you can try through flex + order
.test { display: flex; flex-wrap: wrap; } .test1 { order: -2; } .test3, .test1 { width: 100%; background: gray; margin-bottom: 2px; } .test3:hover ~ .test1 { background: orange; } <div class="test"> <div class="test3">test3</div> <div class="test3">test3</div> <div class="test1">test1</div> </div> Otherwise, only through js
The only adequate way is JS , or using the jQuery library.
function getClass(c) { return document.getElementsByClassName(c)[0]; } let jsFirst = getClass("js-first"), jsThirst = getClass("js-thirst"), jqueryFirst = getClass("jQuery-first"), jqueryThirst = getClass("jQuery-thirst"); function hover(elem, aim) { elem.addEventListener('mouseover', function(e) { aim.classList.add("hover"); }); elem.addEventListener('mouseout', function(e) { aim.classList.remove("hover"); }); } $('.jQuery-first').hover(function(e) { $('.jQuery-thirst').addClass("hover"); }, function(e) { $('.jQuery-thirst').removeClass("hover"); }) hover(jsFirst, jsThirst); *, *:before, *:after {box-sizing: border-box;} body, p, figure, h1, h2, h3, h4, h5, h6 {margin: 0;} ul, ol, dl, li, menu{ margin: 0; padding: 0; list-style: none; } body { display: flex; justify-content: space-around; } .container { display: flex; flex-direction: column; align-items: center; } .native-js { margin-bottom: 20px; } .title { padding: 10px; margin-bottom: 10px; font-weight: bold; font-size: 18px; } .elem { padding: 20px; background: #411; color: #fff; } .elem:not(:last-child) { margin-bottom: 10px; } .hover { background: #241; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="native-js container"> <span class="title">JS</span> <div class="js-first elem">Наведи на меня</div> <div class="js-second elem">2</div> <div class="js-thirst elem">3</div> </div> <div class="jQuery container"> <span class="title">jQuery</span> <div class="jQuery-first elem">Наведи на меня</div> <div class="jQuery-second elem">2</div> <div class="jQuery-thirst elem">3</div> </div> Source: https://ru.stackoverflow.com/questions/799047/
All Articles