Wed Sep 07 2022

i Button Image Caption

CSS3539 views

File Name: image-caption.html

<!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>Image Caption</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Nunito&display=swap" rel="stylesheet"> 
    <style>
        * {
            margin: 0;
            padding: 0;
            font-family: 'Nunito', sans-serif;
        }

        body {
            background-color: #292929;
        }

        section {
            width: 100%;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        #imgSec {
            width: 350px;
            height: 300px;
            background-image: url('https://cdn.pixabay.com/photo/2017/08/07/16/39/girl-2605526_960_720.jpg');
            background-position: center;
            background-repeat: no-repeat;
            background-size: cover;
            position: relative;
            overflow: hidden;
        }

        #imgSec .caption {
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            background-color: rgba(255,255,255,0.1);
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
            clip-path: circle(15px at 93% 7%);
            opacity: 0;
            visibility: hidden;
            transition: 0.3s all ease-in-out;
        }

        #imgSec:hover .caption {
            opacity: 1;
            visibility: visible;
        }

        #imgSec.active .caption {
            opacity: 1;
            visibility: visible;
            clip-path: circle(75%);
            background-color: rgba(255,255,255,0.9);
        }

        #imgSec .caption button[type=button] {
            position: absolute;
            font-size: 20px;
            top: 10px;
            right: 15px;
            background-color: #fff;
            width: 20px;
            height: 20px;
            display: flex;
            justify-content: center;
            align-items: center;
            border-radius: 100%;
            font-weight: bold;
            box-shadow: 0 0 5px 0 #535353;
            cursor: pointer;
            border:none;
        }

        #imgSec .caption p{
            font-size: 18px;
        }
    </style>
    <script>
        function toggleCaption() {
            let imgSec = document.getElementById('imgSec');
            imgSec.classList.toggle('active')
        }
    </script>
</head>
<body>
    <section>
        <div id="imgSec">
            <div class="caption">
                <button type="button" onclick="toggleCaption()">i</button>
                <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Illo enim voluptatum, accusamus voluptatibus id ipsam error veniam accusantium vero saepe nemo quisquam quod. Accusamus aliquam eos doloremque nobis hic magni?</p>
            </div>
        </div>
    </section>
</body>
</html>

Result Screenshot(s)

i Button Image CaptionWorking Sample0

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.