Syntax error What to do with content that renders outside the element box with JavaScript?

What to do with content that renders outside the element box with JavaScript?



If the content renders outside the element box, use the overflow property to add a scroll. This will ease visitors in reading the entire content.

Example

You can try to run the following code to learn how to work with overflow property in JavaScript −

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         #box {
            width: 450px;
            height: 150px;
            background-color: orange;
            border: 3px solid red;
            margin-left: 20px;
         }
      </style>
   </head>
   <body>
      <p>Click to use overflow property and set scroll.</p>
      <button type="button" onclick="display()">Set Scroll</button>
      <div id="box">
         <p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>
         <p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>
         <p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>
         <p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>
         <p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>
         <p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>
      </div>
      <br>
      <br>
      <script>
         function display() {
            document.getElementById("box").style.overflow = "scroll";
         }
      </script>
   </body>
</html>
Updated on: 2020-06-23T13:35:09+05:30

248 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements