所以这是我的代码:
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown:hover .dropdown-content {
display: block;
}
#image1:hover {
filter: brightness(50%);
}
.desc {
padding: 15px;
text-align: center;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h2>Dropdown Image</h2>
<p>Move the mouse over the image below to open the dropdown content.</p>
<div class="dropdown">
<img id="image1" src="https://www.w3schools.com/css/img_5terre.jpg" alt="Cinque Terre" width="100" height="50">
<div class="dropdown-content">
<img src="https://www.w3schools.com/css/img_5terre.jpg" alt="Cinque Terre" width="300" height="200">
<div class="desc">Beautiful Cinque Terre</div>
</div>
</div>
</body>
</html>
正如您所看到的,当您运行它并将鼠标悬停在小照片上时,会出现更大版本(并且较小的版本会变得更暗)。尽管如此,当你从较小的版本转移到较大的版本时,小照片会恢复正常。
有人可能会向我解释当光标在小照片上或者用CSS的大照片时我怎么能让较小的照片变暗(选中)?
非常感谢你提前。
.dropdown {
position: relative;
display: inline-block;
}
.dropdown:hover #image1 {
filter: brightness(50%);
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.desc {
padding: 15px;
text-align: center;
}
<div class="dropdown">
<img id="image1" src="https://www.w3schools.com/css/img_5terre.jpg" alt="Cinque Terre" width="100" height="50">
<div class="dropdown-content">
<img src="https://www.w3schools.com/css/img_5terre.jpg" alt="Cinque Terre" width="300" height="200">
<div class="desc">Beautiful Cinque Terre</div>
</div>
</div>
而不是#image1:hover
,在.content:hover #image1
上应用变暗