Web Design and Web Development Tutorials

Post Page Advertisement [Top]



Hello everyone, In this blog post you will learn how to create a cover-uncover an image using only HTML & CSS.

     



 

HTML CODE:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Cover/Uncover an Image</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
    <link rel="stylesheet" href="style.css">
   
</head>
<body>

    <div class="image-card">
        <input type="checkbox" class="toggle-btn">
        <img src="image.png" alt="">

        <div class="content">
            <i class="fas fa-eye-slash"></i>
            <h3>Sensitive Content</h3>
            <p class="text">This image contains sensitive content which some people may find offensive or disturbing.</p>
        </div>
    </div>

</body>
</html>

 

CSS CODE:

*{
    margin: 0;
    padding: 0;
    font-family: "Montserrat", sans-serif;
    box-sizing: border-box;
}

body{
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-card{
    width: 450px;
    overflow: hidden;
    position: relative;
}

.image-card img{
    width: 100%;
    transition: all .5s ease-in-out;
    filter: blur(20px);
}

.content{
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    text-align: center;
    color: #fff;
    padding: 0 40px;
    transition: .6s;
}

.content h3{
    margin: 10px;
}

.toggle-btn{
    appearance: none;
    position: absolute;
    bottom: 0;
    color: #fff;
    z-index: 1;
    border-top: 1px solid #ffffff50;
    padding: 20px;
    margin: 0 40px;
    width: calc(100% - 80px);
    text-align: center;
    cursor: pointer;
}

.toggle-btn::before{
    content: "See Image";
    transition: .3s;
    font-size: 16px;
}

.toggle-btn:checked ~ img{
    filter: blur(0);
}

.toggle-btn:checked::before{
    content: "Cover Image";
}

.toggle-btn:checked ~ .content{
    pointer-events: none;
    opacity: 0;
}

Download Source Code From HERE

No comments:

Post a Comment

Bottom Ad [Post Page]