【视频号】CSS实现产品卡片hover动画

练习项目1年前 (2023)更新 admin
2,173 0

视频号案例源码

【视频号】CSS实现产品卡片hover动画

HTML代码:

<!doctype html>
<html>
<head>
    <meta charset=”utf-8″>
    <meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
    <title>【视频号】CSS实现产品卡片hover动画</title>
    <link rel=”stylesheet” href=”style.css”>
</head>
<body>
    <div class=”card”>
        <div class=”circle”></div>
        <div class=”content”>
            <h2>Pepsi Cola</h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
            tempor incididunt ut labore et dolore magna aliqua.</p>
            <a href=”https://www.webqdkf.com” target=”_blank”>Buy Now</a>
        </div>
        <img src=”img.png”>
    </div>
</body>
</html>

CSS代码:

*
{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: ‘Poppins’, sans-serif;
}
body
{
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: #fff;
}
.card
{
    position: relative;
    width: 600px;
    height: 350px;
    margin: 20px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    border-radius: 20px;
    transition: 0.5s;
}
.card .circle
{
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 20px;
    overflow: hidden;
}
.card .circle:before
{
    content: ”;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #d83133;
    clip-path: circle(120px at center);
    transition: 0.5s;
}
.card:hover .circle:before
{
    background: #0065c3;
    clip-path: circle(400px at center);
}
.card img
{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    height: 300px;
    transition: 0.5s;
}
.card:hover img
{
    left: 72%;
    height: 500px;
}
.content
{
    position: relative;
    width: 50%;
    left: 20%;
    padding: 20px 20px 20px 40px;
    opacity: 0;
    transition: 0.5s;
    visibility: hidden;
}
.card:hover .content
{
    transition-delay: 0.5s;
    opacity: 1;
    visibility: visible;
    left: 0;
}
.content h2
{
    color: #fff;
    text-transform: uppercase;
    font-size: 2.5em;
    line-height: 1em;
}
.content p
{
    color: #fff;
}
.content a
{
    position: relative;
    color: #fff;
    padding: 10px 20px;
    border-radius: 10px;
    background: #fff;
    color: #111;
    margin-top: 10px;
    display: inline-block;
    text-decoration: none;
    font-weight: 700;
}
@media (max-width: 991px)
{
    .card
    {
        width: auto;
        max-width: 350px;
        align-items: flex-start;
    }
    .card:hover
    {
        height: 600px;
    }
    .card:hover img
    {
        top: 70%;
        left: 50%;
        height: 320px;
    }
    .card .content
    {
        width: 100%;
        left: 0;
        padding: 40px;
    }
}
@media (max-width: 420px)
{
    .card .content
    {
        padding: 30px;
    }
    .card:hover img
    {
        height: 300px;
    }
}

 

 

 

 

© 版权声明

相关文章

暂无评论

暂无评论...