The HTML Comment Box is unable to expand its height automatically

I found a code snippet online to create a comment box in HTML. It's working fine, but as more comments are added, they start overflowing and don't stay within the designated box. I've tried using a div with overflow settings, but the issue persists. I'm struggling to find a solution.

Below is the CSS that I have implemented:


    <style>
    #details {
    display : block;
    background-color : #9494FF;
    height : 20px;
    width : 130px;
    padding : 4px;
    border-radius : 10px;
    border : 1px solid black;
    cursor : pointer;
    }

    summary::-webkit-details-marker {
        display: none
        }

    textarea {
    resize : none;
    }

    #para {
    display : block;
    overflow : none;
    height : 200px;
    width : 100%;
    resize : none;
    }

</style>

And here is the main code section:

<ul>

<form>
<textarea id="words" rows="3" cols="60">Enter Comment</textarea>
<input type="button" onclick="getwords()" value="Comment" /> <br>
<details id="details"><summary><center>View Comments</center></summary><div id="para"></div></details>
</form>

<script type="text/javascript">
function getwords() {
  text = words.value;
  document.getElementById("para").innerHTML += '<div>'+text
  document.getElementById("words").value = "Enter Comment"
}
</script>

</ul>

Answer №1

To apply the scrolling effect to the wrapping div, add this style

overflow: auto;

within your CSS stylesheet

Answer №2

Take out the resize none feature, which prevents it from expanding in size.

textarea {
   resize : none; /* Delete this */
}

Answer №3

To display a scrollbar, you need to update the CSS property from overflow: none to overflow: auto

Answer №4

Remember to include the overflow property for the paragraph

#para {
    display : block;
    overflow : auto;
    height : 200px;
    width : 100%;
    resize : none;
    }

Ensure you close the JS string with a proper tag

<script type="text/javascript">
function getwords() {
  text = words.value;
  document.getElementById("para").innerHTML += '<div>'+ text + '</div>' 
  document.getElementById("words").value = "Enter Comment"
}
</script>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Determine which checkbox is currently selected in Vue and send corresponding data based on the checked status

A radio form that is conditionally disabled by another checkbox. One radio button can send either true or false and the other has an input that sends some data. How can I determine which radio button is checked and decide whether to send true/false or the ...

Utilizing React's createRef() for Enzyme testing

I am currently using the new React.createRef() api in one of my components. I am trying to figure out how to test if document.activeElement is equal to the current ref component. Here is the component code: export class Automatic extends Component { c ...

What is causing this animation to malfunction?

Could someone assist me in hiding this div-container for a brief period of 2 seconds? If you have any alternative suggestions, feel free to share them but, please refrain from using jQuery or JavaScript. #vcontainer { height: 450px; width: 100%; ba ...

Encountering an error in Strapi project: URL undefined

I am currently in the process of setting up a Strapi application and getting it up and running. Following the instructions provided in this document: After successfully setting up Strapi and creating the application, I encountered an error when trying to ...

The jQuery datepicker fails to function properly on an HTML element that has been added via AJAX

In the page header, I have a jQuery datepicker function bound to the "birthday" input HTML element: <script type="text/javascript"> $(function() { $( "#birthday" ).datepicker(); }); </script> After that, some AJAX functionali ...

Unable to view image stored as a blob

https://i.stack.imgur.com/8v90u.pngI have been studying these examples PHP display image BLOB from MySQL How to display an BLOB image stored in MySql database? They all demonstrate the same method of displaying images saved as blob. In my case, I ha ...

Adjusting the size of a bug while hovering over a specific div

Having recently started learning HTML & CSS, I have a question regarding creating a box that scales from 1.0 to 0.8 when hovered over with the mouse. The scaling works perfectly when hovering in the middle (0.0 to 0.8) of the box. However, when hover ...

Display various React components for widgets

I am looking to display multiple instances of a widget in html. I have 3 divs with the same id, each with different attributes, and I want to render my react component three times on the page. Currently, I am only able to display the first component. Here ...

Embed images within the JavaScript bundle

Here is my scenario: I have developed a components library for React. Within this library, there is a package bundled with Rollup that contains various assets, including a GIF picture used in one of the components. The specific component utilizing this p ...

A guide on converting an HTML tag ID to a PHP string

I am currently working on a project that is giving me some trouble with errors. I have created an HTML file called name.html and a PHP file named result.php. In the HTML file, I included some JavaScript to take us to result.php when we click on the Submit ...

Choose a row from a table by utilizing AJAX with jQuery

Need help with deleting specific table rows using AJAX? The goal is to send the ID and Printer Type values from the table data cells when a row is selected for deletion. <table class="u-full-width" > <thead> <tr> ...

Different kinds of garbage collection operations in NodeJS

When utilizing the perf_hooks module in NodeJS, we have access to information regarding garbage collection. This can be achieved by using PerformanceObserver, which is triggered with each garbage collect event. const obs = new perf_hooks.Performanc ...

What is the reason behind the fact that using margin: auto 0px; does not result in vertical centering of a block, whereas margin: 0px auto;

To effortlessly set the width to auto, use margin:0px, auto #container{ background-color: blue; height:600px; width:600px; margin:0px auto;} <div id="container"></div> However, why is it not possible to set the height to auto with margin:au ...

How to Upload Your Avatar Image with the Stream-Chat API from GetStream.io

I am currently in the process of developing a Stream-Chat API project and I want to allow users to upload images directly from their devices. Upon testing, everything seems to be working fine, but the uploaded image is not displayed - only the default avat ...

Capture the item selected from the dropdown using ng-model to retrieve the name instead of the

I need help getting the name/text/html of the selected option in a dropdown using angular.js, rather than just its value. Currently, I have this setup which retrieves the value: Here is my HTML code snippet <select class="SelectCar" ng-model="Selected ...

The customization of a class within an array loop is not functioning properly

I'm facing an issue where I've added a class (question) to each element in an array, and the loop is running smoothly. However, I'm having trouble getting jQuery to recognize the class - it's almost as if it doesn't exist... I sus ...

Using a for loop in JavaScript to dynamically display TextBoxFor(model=> model[i].prop) in an MVC application

I need some help getting this code to function correctly: $('#ddl').change(function () { $('#cont').html(''); var count = getCount($('#ddl').val()) for (var i = 0; i < count ; ...

How can I create a fixed navigation menu in Wordpress that always stays at the top of the page?

I'm currently using the default Wordpress theme Twenty Twelve for my website located at: . My goal is to have the navigation menu always stay at the top of the page while scrolling, similar to a site called wpsites (I can't provide the link due ...

Issue with displaying custom error message on Mysqli connection

Currently following a tutorial from an individual who has provided the below code snippet: <?php require_once "connect.php"; $connection = @new mysqli($host, $db_user, $db_password, $db_name); if ($connection->connect_errno != 0) { e ...

Prevent past date and time selection in "date" text-box mode using ASP.NET

Is there a way to prevent users from selecting past dates and times in a textbox with TextMode set to DateTime? I was able to achieve this using a calendar control, but my specific requirement is to implement it only within the textbox itself. protected ...