以下是我的卡片组件转换的摘录。当它悬停在盒子阴影上时,我有一个过渡。悬停时似乎很平滑,而悬停时似乎不太流畅(似乎有点尖锐)。
我在CSS中错过了什么?
这是我的小提琴-https://jsfiddle.net/zxfb981r/
.wrapper {
display: flex;
justify-content: center;
align-items: center;
font-size: 1rem;
height: 7.75rem;
transition: all 300ms;
box-shadow: 0 2px 4px 0 rgba(224, 224, 224, 0.5);
border: solid 1px #F5F5F5;
}
.wrapper:hover{
box-shadow: 0 2px 14px 0 rgba(0, 0, 0, 0.4);
transition: opacity 200ms ease-in-out;
}
.imageContainer {
flex: 0 0 33%;
height: 100%;
}
.image {
width: 100%;
height: 100%;
object-fit: cover;
}
.content {
flex: 1;
text-align: left;
margin: 0 1.1825rem;
}
.title {
font-size: 1rem;
margin: 0 0 0.25rem 0;
padding: 0;
}
.price {
color: #BAA082;
font-size: 0.875rem;
text-transform: uppercase;
margin: 2rem 0 0;
padding: 0;
}
@media(min-width: 46.5rem) {
.wrapper {
height: 8.75rem;
}
.title {
font-size: 1.1875rem;
}
.price {
font-size: 1rem;
}
}
<div class="wrapper">
<div class="content">
<h4 class="title">Point of sale</h4>
<p>Point of sale</p>
<p class="price">From £165</p>
</div>
<div class="imageContainer">
<img src="https://images.unsplash.com/photo-1556742521-9713bf272865?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2134&q=80" alt="" class="image"></div>
</div>
从opacity
中删除transition
会给您想要的结果。检查代码段。
.wrapper {
display: flex;
justify-content: center;
align-items: center;
font-size: 1rem;
height: 7.75rem;
transition: all 300ms;
box-shadow: 0 2px 4px 0 rgba(224, 224, 224, 0.5);
border: solid 1px #F5F5F5;
}
.wrapper:hover{
box-shadow: 0 2px 14px 0 rgba(0, 0, 0, 0.4);
transition: 200ms ease-in-out;
}
.imageContainer {
flex: 0 0 33%;
height: 100%;
}
.image {
width: 100%;
height: 100%;
object-fit: cover;
}
.content {
flex: 1;
text-align: left;
margin: 0 1.1825rem;
}
.title {
font-size: 1rem;
margin: 0 0 0.25rem 0;
padding: 0;
}
.price {
color: #BAA082;
font-size: 0.875rem;
text-transform: uppercase;
margin: 2rem 0 0;
padding: 0;
}
@media(min-width: 46.5rem) {
.wrapper {
height: 8.75rem;
}
.title {
font-size: 1.1875rem;
}
.price {
font-size: 1rem;
}
}
<div class="wrapper">
<div class="content">
<h4 class="title">Point of sale</h4>
<p>Point of sale</p>
<p class="price">From £165</p>
</div>
<div class="imageContainer">
<img src="https://images.unsplash.com/photo-1556742521-9713bf272865?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2134&q=80" alt="" class="image"></div>
</div>