Friday 25 February 2022

How to change image on hover with CSS

using background :-



<!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("logo.png") no-repeat;

        display: inline-block;

    }

    .card:hover {

        background: url("tushar.jpg") no-repeat;

    }

</style>

</head>

<body>

    <div class="card"></div>

</body>

</html>


another example :- 


<!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="logo.png" alt="Card Back"    width=130px

        height=195px>

        <img src="tushar.jpg" class="img-top" alt="Card Front" width=130px

        height=195px>

    </div>

</body>

</html>

No comments:

Post a Comment