[英]Change hovered card background color using sass
I need background color lightgreen
on card hover.我需要的背景颜色
lightgreen
卡上悬停。
<div class="card">
<img src="https://placekitten.com/200/300"
alt="card-theme"/>
<div class="hovered-text">
Open
</div>
</div>
styles样式
.card {
background: white;
width: 200px;
height: 200px;
position: relative;
border: 5px solid lightgrey;
border-radius: 2px;
display: flex;
justify-content: center;
align-items: center;
.hovered-text {
display: none;
position: absolute;
color: salmon;
}
img {
width: 100%;
height: 100%;
object-fit: cover;
opacity: 1;
&:hover {
opacity: 0.1;
background: lightgreen;
}
&:hover~.hovered-text{
display: block
}
}
}
Please help to make it work.请帮助使其工作。 Thanks
谢谢
All you need to do is add hover to the class card.您需要做的就是将悬停添加到课程卡上。 Eg:
例如:
.card {
&:hover {
background: lightgreen;
}
Example:例子:
card {
background: white;
width: 200px;
height: 200px;
position: relative;
border: 5px solid lightgrey;
border-radius: 2px;
display: flex;
justify-content: center;
align-items: center;
&:hover {
background: lightgreen;
}
.hovered-text {
display: none;
position: absolute;
color: salmon;
}
img {
width: 100%;
height: 100%;
object-fit: cover;
opacity: 1;
&:hover {
opacity: 0.1;
background: lightgreen;
}
&:hover~.hovered-text{
display: block
}
}
}
Change your .card backgroundcolor to lightgreen将您的 .card 背景颜色更改为浅绿色
.App {
font-family: sans-serif;
text-align: center;
}
.card {
background: lightgreen;
width: 200px;
height: 200px;
position: relative;
border: 5px solid lightgrey;
border-radius: 2px;
display: flex;
justify-content: center;
align-items: center;
.hovered-text {
display: none;
position: absolute;
color: salmon;
}
img {
width: 100%;
height: 100%;
object-fit: cover;
opacity: 1;
&:hover, ::after {
opacity: 0.3;
// background: #lightgreen;
}
&:hover~.hovered-text{
display: block;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.