Change Image on hover

Change image on hover with CSS

Example 1:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Change Image on Hover in CSS</title>
<style>
    .card {
        width: 130px;
        height: 195px;
        background: url("images/card-back.jpg") no-repeat;
        display: inline-block;
    }
    .card:hover {
        background: url("images/card-front.jpg") no-repeat;
    }
</style>
</head>
<body>
    <div class="card"></div>
</body>

</html>

Example 2:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Image Swap on Hover with CSS</title>
<style>
    .card {
        width: 130px;
        height: 195px;
        position: relative;
        display: inline-block;
    }
    .card .img-top {
        display: none;
        position: absolute;
        top: 0;
        left: 0;
        z-index: 99;
    }
    .card:hover .img-top {
        display: inline;
    }
</style>
</head>
<body>
    <div class="card">
        <img src="images/card-back.jpg" alt="Card Back">
        <img src="images/card-front.jpg" class="img-top" alt="Card Front">
    </div>
</body>

</html>

Comments