Tips for setting up a Bootstrap textarea element to fully occupy the parent div height

I am working with bootstrap along with plain HTML and CSS. In my code, there is a <div> containing two child divs. The first child <div> includes a Bootstrap form-group and a btn-primary. I want the text entry form inside this div to expand vertically and fill the entire available height of the parent <div>, in this case identified as class="rightupper". Currently, I have set the height of the textarea using inline CSS as style="height: 30vh;", however, it's not fitting/filling the container vertically as desired. The width adjustment seems to be functioning properly.

Below is the HTML snippet:

<div class="right">
        <div class="rightupper">
            comments:
            <hr>
            <div class="form-group">
                        
                <textarea class="form-control w-100" style="height: 30vh;" id="descriptionInput" rows="3"></textarea>
            </div>
            <button class="btn btn-primary" type="button">Click Btn</button>

        </div>    
        <div class="rightlower">
            out text
            <hr>
        </div>
    </div>
</div>

What adjustments should be made to either the

<div class="form-group">
or the
<textarea class="form-control w-100" style="height: 30vh;" id="descriptionInput" rows="3">
to ensure vertical fitting/filling within the parent div?

Here is the relevant CSS for these divs;


.right {
  height: 100vh;
  width: 20%;
  border: 2px solid blue;
}
.rightupper {
  height: 50vh;
  width: 100%;
  background-color: rgb(190, 190, 190);
}
.rightlower {
  height: 50vh;
  width: 100%;
  background-color: rgb(190, 190, 190);
  border-top: 5px solid blue;
}

Answer №1

I came up with two different strategies.

The first one is a straightforward workaround.

To make it easier to adjust the width when the resolution changes, I shifted the focus from 20% of the width to col-3 which Bootstrap recognizes as roughly 20%. In the example provided, I demonstrated how 50% of the width is utilized when the resolution decreases. This setting can be customized later on.

In order to occupy the full space (or about 60% to accommodate the title and button), I employed the css .form-group to reference the specified elements along with the textarea tag (#descriptionInput) taking up 100% of the space within the preceding div.

Although this approach is workable, I find it somewhat inconvenient due to the necessity of making height adjustments for varying resolutions, which must be addressed through breakpoints.

view codeply demonstration

The second strategy relies on FLEX.

This method leverages flex properties inherent in bootstrap 4.

The concept involves creating zones where you can configure how flex positions the objects based on resolution changes.

Flex operates on the parent-child relationship paradigm. When applying flex to the parent element, you are essentially dictating how its child elements will respond.

You'll notice that I introduced classes (title, text, and bot) to grant unique behavior configurations to each component. Custom settings within the css ensure that the textarea spans 100% of the space while the rest occupies only 5vh.

This versatile setup allows for easy customization across resolutions, enabling adaptive height adjustments.

explore codeply demo

For a more comprehensive understanding of this approach, refer to this link

Wishing you success!

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

Apply pointer style to the CSS only when a division contains text

If there is plain text inside a div with class="x95qze", how can we add cursor:pointer only to the second div that contains the text Cursor pointer required here. The div with class="x95qze" will not change. The content of the div may ...

Tips for passing down CSS styles through Less stylesheets

In an effort to create a legend below a <table> that matches the colors defined in Bootstrap stylesheets, I am struggling with the following: .table > thead > tr > td.warning, .table > tbody > tr > td.warning, .table > tfoot ...

What is the best way to resize a div to fit its content if 'clear:both' and 'float:left' are not working as desired?

I've been struggling to find a solution for an issue with my HTML. I have three 'divs' that need to display different information in their own line, enclosed in a parent element with a centered border. Despite trying solutions like inline-bl ...

The footer of the website remains separate from the overlay of the modal Popup Form

I recently implemented a modal popup form on my website that covers the entire viewport with its background. However, I am facing an issue where the footer of the website is still displayed on top of the modal background, even though everything else seems ...

If the children contain multiple div elements in jQuery

Is there a way to determine the number of divs inside a li element? Below is the code I've tried, but it's not functioning as expected. (The issue is that every img receives the class, even when there's only 1 div inside the li.) if($(&apo ...

Elevate with Ease: Tailwind's Height Transition

I've been attempting to implement a transition effect using TailwindCSS, but I haven't found an updated version with the latest features. Here's the code snippet: <div id="fadeInElement" className={visible ? " w-2/3 px-5 t ...

jquery conflict between parent div hover function and child's hover function

I am experiencing an issue with a hover function on a parent element and child event. It seems that the child hover function is not working when hovering over the parent. Specifically, I have set up a hover function on both the "univ" div and the "heading ...

React Redux has encountered an error as mapStateToProps and a variable are not defined in the code

I encountered the following error message: ./src/components/Playing.jsx Line 15: 'aaa' is not defined no-undef within my Playing.jsx file: import React, { Component } from 'react' console.log(aaa); Referencing Token.jsx: i ...

Adjust the cell text overflow based on the width of the table

I am working with a table that has multiple columns. I want the first 3 columns to have a larger width than the others, specifically taking up 15% each for a total of 45% of the table's width. Currently, I am using this code in a sandbox environment: ...

Problem with CSS related to JQuery chosen library

I am currently utilizing the Jquery Chosen plugin and experiencing a CSS dilemma. There is a placeholder text that says "Select some options" by default when using Chosen. However, when it is displayed, the text is being truncated. Even though I have set ...

Utilize jQuery to apply inline styles to dynamically created div elements

I am attempting to apply inline styles to a div using jQuery. The current state of the div, as seen in Firebug, is shown below: https://i.sstatic.net/rqhIc.jpg My goal is to retain the existing CSS while adding margin-left:0 and margin-right:0 to the cur ...

Eliminate uniform column heights in Bootstrap 4 rows

Exploring the latest version of Bootstrap, I am experimenting with the updated grid system to create two columns. Here's the code snippet in this JSFiddle: <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" r ...

Tips for ensuring that all children within a flex-container have equal heights

I seem to be facing an issue with this problem. My goal is to ensure that all the child divs within a flex container have the same height as the tallest child div, which in this case is 100px. Additionally, I want them to be aligned at the center. I&apos ...

Step-by-step guide on making a cascading dropdown menu using HTML

I am trying to create a file with two dropdown menus, where the options in the second dropdown are based on the selection made in the first dropdown. Although I have never worked with HTML before and feel a bit lost, I attempted to modify code from a tutor ...

Applying Vue Quill CSS to the initial Quill Editor component exclusively and tips for personalizing the toolbar

I have encountered an odd CSS issue while using the vue-quill package in my project. Each comment has its own quill editor for replying, and I temporarily set the isOpen prop to true for debugging purposes. This results in a quill editor being displayed un ...

Loop through the list items using jQuery and retrieve the value of the data-imgid attribute

Multiple li elements have a unique data-id attribute, as shown below: <ul> <li data-imgid="5" class="getMe">some text</li> <li data-imgid="6" class="getMe">some text</li> <li data-imgid="7" class="getMe">some t ...

Utilizing HTTPS for all links in the source code of Magento

Recently, I encountered a situation while installing a fresh version of Magento v1.7.0 on my VPS running nginx. After uploading the clean install to public_html, unzipping it, and attempting to run the install by entering my IP (xx.x.xxx.xxx:8086), I initi ...

The Influence of the Navigation Division on Other Navigation Components

My main navigation consists of multiple div elements. Each page has a separate div element for the active link, causing its height to be higher. This seems to be affecting the line height and position of the other divs on the page. Below is my SASS code: ...

Determining the Ideal Size for Expandable Text Headers

I need help adjusting the spacing between headers on my expandable sections, similar to what is shown here. I have managed to change the font size but as I increase it, the headers start to overlap. I am quite new to this so forgive me if this is a simple ...

When the pointer events for table data are disabled, the table row (<tr>) will not be able to receive any pointer events

I have a basic table with different data displayed in rows and columns. I want to make the entire row clickable so that when clicked, something happens. By default, the <td> elements inside the table act as event targets, but I specifically want onl ...