【发布时间】:2017-05-22 07:26:40
【问题描述】:
我正在尝试在悬停时突出显示一个项目,同时降低其他项目的“亮度”,因此重点放在悬停项目上。我的商品由图片、尺寸选择器和添加到购物车按钮组成。我想要的是当鼠标悬停在这些部分中的任何一个上时,这三个部分同时突出显示。我只想用 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
【问题讨论】:
标签: javascript html css reactjs