gpt4 book ai didi

javascript - 如何修复我的悬停效果以突出显示所选元素?

转载 作者:行者123 更新时间:2023-11-28 03:46:05 24 4
gpt4 key购买 nike

我正在尝试在悬停时突出显示一个元素,同时降低其他元素的“亮度”,因此重点放在悬停元素上。我的商品由图片、尺寸选择器和添加到购物车按钮组成。我想要的是当鼠标悬停在其中任何一个部分上时,这三个部分同时突出显示。我只想用 CSS 来做到这一点,并设法让我想要的有点工作,除非鼠标悬停在添加到购物车按钮或选择器上,只有那些元素会突出显示。这是我的 CSS:

   #Productlist {
list-style-type: none;
position: relative;
display: inline-block;
margin-top: 100px;
}

.Product img {
width: 350px;
height: 400px;
display: inline-block;
position: relative;
left: 50px;
margin-top: 100px;
}

.Product:hover img {
opacity: 1;
}

#Productlist:hover img{
opacity: 0.5;
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}

.Product button {
background-color: #141516;
position: relative;
right: 134px;
display: inline-block;
z-index: 1;
padding: 15px 45px;
line-height: 1.8;
text-align:center;
text-transform:uppercase;
font-size:0.8rem;
font-weight:600;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
border: 3px solid white;
}

.Product button a {

position:relative;
padding:0px;
text-align:center;
text-transform:uppercase;
color:#888888;
font-size:0.8rem;
font-weight:600;
line-height:60px;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;

}

.Product button:hover a {

color:red;
z-index: 1000;
}

.Product button:hover {

color:black;
background-color: white;
border: 1px solid white;
}

#size{
display: inline-block;
z-index: 1;
color: white;
position: relative;
right: 484px;
border: 3px solid white;
width: 120px;
height: 40px;
border-radius: 3px;
overflow: hidden;
background: #141516 url("img/icon-select.png") no-repeat 90% 50%;
}

#size:focus {
outline: none;
}

这是我的 HTML:

    <div className='Webshop' id='Webshop'>
<li id="Productlist">
<div className='Product'>
<img src={Seltzshirt}></img>
<button onClick={this.handleClick} className="addit">Add to cart</button>
<select id="size" onChange={this.change} value={this.state.value}>
<option value="medium">Medium</option>
<option value="large">Large</option>
<option value="x-large">X-large</option>
</select>
</div>
<div className='Product'>
<img src={Seltzshirt}></img>
<button onClick={this.handleClick} className="addit">Add to cart</button>
<select id="size" onChange={this.change} value={this.state.value}>
<option value="medium">Medium</option>
<option value="large">Large</option>
<option value="x-large">X-large</option>
</select>
</div>
</li>
</div>

更新

我更新了我的 CSS 和 HTML 以显示我所做的一些更改并应用了 Michael Coker 的建议。现在,当我将鼠标悬停在图像、按钮或选择器上时,所有图像都会变暗,而选择器和按钮都会保持突出显示。为什么我的 .Product img 在悬停时忽略更改 opacity: 1;

我制作了这个 CodePen 来展示我的问题:https://codepen.io/Feners4/pen/xdQmyQ

最佳答案

使用 #Productlist:hover img { opacity: .5; 更改所有图像的不透明度},并使用 #Product:hover img { opacity: 1; 排除当前的。 }

#Productlist {
list-style-type: none;
position: relative;
display: inline-block;
margin-top: 100px;
}

#Product img {
width: 350px;
height: 400px;
display: inline-block;
position: relative;
left: 50px;
margin-top: 100px;
}

#Productlist:hover img {
opacity: 0.5;
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}

#Product:hover img {
opacity: 1;
}

#Webshop button {
background-color: #141516;
position: relative;
right: 134px;
display: inline-block;
z-index: 1;
padding: 15px 45px;
line-height: 1.8;
text-align: center;
text-transform: uppercase;
font-size: 0.8rem;
font-weight: 600;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
border: 3px solid white;
}

#Webshop button a {
position: relative;
padding: 0px;
text-align: center;
text-transform: uppercase;
color: #888888;
font-size: 0.8rem;
font-weight: 600;
line-height: 60px;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
}

#Webshop button:hover a {
color: red;
z-index: 1000;
}

#Webshop button:hover {
color: black;
background-color: white;
border: 1px solid white;
}

#size {
display: inline-block;
z-index: 1;
color: white;
position: relative;
right: 484px;
border: 3px solid white;
width: 120px;
height: 40px;
border-radius: 3px;
overflow: hidden;
background: #141516 url("img/icon-select.png") no-repeat 90% 50%;
}

#size:focus {
outline: none;
}
<div className='Webshop' id='Webshop'>
<li id="Productlist">
<div id='Product'>
<img src=http://kenwheeler.github.io/slick/img/lazyfonz2.png></img>
<button onClick={this.handleClick} className="addit">Add to cart</button>
<select id="size" onChange={this.change} value={this.state.value}>
<option value="medium">Medium</option>
<option value="large">Large</option>
<option value="x-large">X-large</option>
</select>
</div>
<div id='Product'>
<img src=http://kenwheeler.github.io/slick/img/lazyfonz2.png></img>
<button onClick={this.handleClick} className="addit">Add to cart</button>
<select id="size" onChange={this.change} value={this.state.value}>
<option value="medium">Medium</option>
<option value="large">Large</option>
<option value="x-large">X-large</option>
</select>
</div>
<div id='Product'>
<img src=http://kenwheeler.github.io/slick/img/lazyfonz2.png></img>
<button onClick={this.handleClick} className="addit">Add to cart</button>
<select id="size" onChange={this.change} value={this.state.value}>
<option value="medium">Medium</option>
<option value="large">Large</option>
<option value="x-large">X-large</option>
</select>
</div>
<div id='Product'>
<img src=http://kenwheeler.github.io/slick/img/lazyfonz2.png></img>
<button onClick={this.handleClick} className="addit">Add to cart</button>
<select id="size" onChange={this.change} value={this.state.value}>
<option value="medium">Medium</option>
<option value="large">Large</option>
<option value="x-large">X-large</option>
</select>
</div>
</li>
</div>

关于javascript - 如何修复我的悬停效果以突出显示所选元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43969774/

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