CSS만으로는이 기능을 사용할 수 없습니다. there's no previous sibling selector in CSS 때문입니다.
<div class="container">
<div id="box1" class="card">
<h1>one</h1>
<p>some text here</p>
</div>
<div id="box2" class="card">
<h1>two</h1>
<p>some text here</p></div>
<div id="box3" class="card">
<h1>three</h1>
<p>some text here</p></div>
</div>
이 같은 선택에 #box1
을 유혹 할 때 #box2
및 #box3
를 선택할 수 있습니다 : 당신이 #box2
또는 #box3
를 가져 가면
div[id^="box"]:hover ~ div[id^="box"] {
//blurry stuff
}
을하지만 일이
은 그래서이 마크 업을 부여? 마우스를 가져 가기 전에 상자를 변경할 수 없습니다.
우리는 거꾸로 생각하고 기본적으로 흐리게 처리 한 다음 간단한 :hover
선택기를 사용하여 사용자가 가리키고있는 것을 제거 할 수 있습니다. 그런 식으로 당신은 당신이 떠오르지 않은 사람으로 끝나지 만, 상자가 정상적으로 보이지 않기 때문에 당신이 원하는 것이 아닙니다.
다음은 jQuery의 .not()을 사용하여 작동하는 간단한 방법의 예입니다. 원하는 경우 CSS를 함수에 넣는 대신 클래스를 토글하여 흐리게 처리 할 수 있습니다.
$(function(){
var boxes = $('div[id^="box"]');
$(boxes).on('mouseenter', function(){
$(boxes).not($(this)).css('background-color', 'red');
}).on('mouseleave', function(){
$(boxes).css('background-color', 'initial');
});;
});
.container {
width: 100%;
margin: 0 auto;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: space-between;
}
.card {
border: solid black 1px;
padding: 20px;
-webkit-box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);
box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);
}
body {
margin: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div id="box1" class="card">
<h1>one</h1>
<p>some text here</p>
</div>
<div id="box2" class="card">
<h1>two</h1>
<p>some text here</p></div>
<div id="box3" class="card">
<h1>three</h1>
<p>some text here</p></div>
</div>
최종 참고 : 헤더 태그를 수정해야합니다. 두 번째 및 세 번째 헤더의 경우 시작 태그는 <h1>
개이고 닫는 태그는 </h2>
개입니다.
질문에 코드를 추가해야합니다. 그 외에도 Codepen 링크를 추가 할 수 있지만 위조 코드로 링크를 게시하여 질문을 게시하는 코드 요구 사항을 피하려고하지 마십시오. 아마 왜 당신이 downvoted지고있어. – cjl750
편집 요청이 많아서 게시물을 편집 할 수 없지만 질문 자체에 코드를 추가하십시오 (Stack Overflow에는 CodePen과 매우 유사한 샌드 박스가 내장되어 있습니다). –