gpt4 book ai didi

html - 在悬停另一个元素时更改元素的属性

转载 作者:太空宇宙 更新时间:2023-11-03 22:43:00 25 4
gpt4 key购买 nike

我有两个不同的 div,悬停在一个 div 上时,我试图更改此 div + 另一个 div 的属性(框阴影)。即在下面的例子中,div one-two 悬停时,one-two 和 one-one 都应该添加 box-shadow。

我在 stackoverflow 中找到了一些答案,上面写着 .div1:hover + .div2,但这似乎不起作用。 (Is there any way to hover over one element and affect a different element?)。还有其他解决方案还是我做错了什么?

@import url(https://fonts.googleapis.com/css?family=Open+Sans:700,300);
.container {
display: block;
max-width: 100%;
}
.header {
width: 100%;
position: absolute;;
/*border-bottom: 1px solid black;*/
height: 10%;
background-color: teal;
margin: -9px;
padding-top: 15px;
box-shadow: 2px 5px 4px #ccc ;
text-align: center;
font-size: 20px;
text-transform: uppercase;
font-family: sans-serif;
font: Helvetica;
color: #ccc

}
.canvas-frame {
position: absolute;
left: 30%;
top: 20%;
width: 600px;
height: 400px;
background: linear-gradient(to left bottom, #2DBE60, #246DE9);
box-shadow: 3px 3px 5px 2px #ccc;
}
.frame {
position: absolute;
left: 30%;
top: 20%;
width: 600px;
height: 400px;
background: linear-gradient(to left bottom, #2DBE60, #246DE9);
box-shadow: 3px 3px 5px 2px #ccc;
}
.one-one {
position: absolute;
z-index: 0;
top: 0;
left: 36px;
height: 40px;
width: 20px;
background: #fff;
margin-top:30px;
border-radius: 3px;
transform: rotate(50deg);
box-shadow: 0 0 13px 0 rgba(0,0,0,0.2);
}
.one-two {
position: absolute;
background: #fff;
height: 100px;
width: 20px;
border-radius: 3px;
margin-top : -20px;
top: 51px;
left: 51px;
z-index: 1;
box-shadow: 0 0 13px 0 rgba(0,0,0,0.2);
}
.zero-one,.zero-two {
position: absolute;
z-index: 2;
top: 50;
left: 62px ;
box-sizing: border-box;
height: 100px;
width: 100px;
margin-top : 30px;
border-radius: 50%;
border: 24px solid #fff;
box-shadow: 0 0 13px 0 rgba(0,0,0,0.2);
}
.zero-two {
left: 152px !important;
}
.overlap-text {
position: absolute;
z-index: 1;
}
.big{
font-family: sans-serif;
font: Helvetica;
font-size: 80px;
color: #fff;
text-transform: capitalize;
}
.days{
position: absolute;
top: 90px;
left: 140px;
}
.one-two:hover + .one-one{
box-shadow: 5px 5px 8px 0 #545050;
cursor: -webkit-grab;
}
.one-two:active{
box-shadow: 6px 6px 4px 0 #545050;
cursor: -webkit-grab;
}
.one-two:hover + .one-one{
box-shadow: 5px 5px 8px 0 #545050;
cursor: -webkit-grab;
}
.one-two:active{
box-shadow: 6px 6px 4px 0 #545050;
cursor: -webkit-grab;
}
<html>
<title>
100 days Challenge
</title>
<link rel="stylesheet" href="style.css">
<body>
<div class="container">
<nav class="header"> css challenge </nav>
<div class="frame">
<!-- <canvas class="canvas-frame"> -->
<!-- <h1 class="overlap-text"> 100 </h1> -->
<div class="one-one" id="one-one"></div>
<div class="one-two" id="one-two"></div>
<div class="zero-one"></div>
<div class="zero-two"></div>
<div class="days"><h1 class="big"> days </h1></div>

<!-- <h2> css challenge </h2> -->
</div>
<!-- </canvas> -->
</div>
</body>
</html>

最佳答案

是的,所以你想使用相邻的选择器 +

.one-one:hover + .one-two { box-shadow: 5px 5px 8px 0 #545050; }

以为你做错了顺序就完了

查看这个简单的代码笔示例:http://codepen.io/StefanBobrowski/pen/ZeZGmQ

关于html - 在悬停另一个元素时更改元素的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43216520/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com