Read more Read less using HTML,CSS,JS

Read more / Read less using HTML,CSS,JS.


Hello everyone so today we are sharing a small program for read more/read less effect

here we are using HTML+CSS+JS to apply the effect.



 

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Read More</title>
    <link rel="stylesheet" href="styles.css">

</head>
<body>
    
    <div id="article">

        something Text...

    </div>

    <center><button id="btn" onclick="read()">Read More</button>
    </center>
</body>

    <script src="script.js">
    </script>
</html>

style.css



*{margin: auto 0;}
#article{
    box-sizing: border-box;
    background-color: #fff;
   max-height200px;
    overflow: hidden;
    border:3px solid transparent;
    padding20px;
        }
#article.more{
overflow: visible;
background-color:#fff;
max-height: fit-content;
        }
#btn{
    background-color: blue;
    padding20px;
    font-size25px;
    border-radius63px 63px 63px 63px;
     border0px solid #000000;
    }
#btn:hover{
opacity0.7;
}

scripts.js

function read(){
    var check=document.getElementById("article");
    var btn=document.getElementById("btn");
        if(check.className ==''){
            check.className='more';
            
            btn.innerText="Read less";
                }
        else{
        check.className='';
        btn.innerText='Read More';
        }

    }

so that's it for today guys.

thank you.

No comments: