Unable to set the max-height to 100% on textarea in CSS

Within my div, I have a layout consisting of a header, textarea, and footer. The header and footer adjust their size based on content, while the textarea fills the remaining space. To ensure the textarea does not exceed 100% height, I set its max-height to be 100%. However, when resizing the textarea, it can expand beyond the parent's 100%. How can this issue be resolved?

View the code here: http://jsfiddle.net/FC7eY/1650/

Key Points:

  • The cumulative heights of all elements should equal 100%
  • The height of the textarea-wrapper div should be calculated as
    totalHeight(100%) - headerHeight - footerHeight
  • The header and footer sizes are dynamic and depend on content
  • The parent/wrapper div must have a height of 80% and a width of 350px

Answer №1

To ensure all elements are visible on the screen regardless of size, you can utilize calc CSS for adjusting the height and width of textareas. By using display table and table-row properties, you can effectively manage element visibility across different screen sizes. To dynamically set the height of a textarea while excluding header and footer heights, consider implementing the following approach: ** For an updated example, refer to this Updated Fiddle for the CSS modifications.

UPDATE: The second div will now occupy the remaining height and width without horizontal overflow

html,
body,
* {
  margin: 0;
  padding: 0;
}

.wrap {
  width: 350px;
  height: 80%;
  display: table;
  border: 3px solid magenta;
}

.wrap > div {
  background: red;
  display: table-row;
  height: 0;
}

#textarea-wrapper {
  background: pink;
  height: auto;
}

#text {
  max-width: calc(350px - 3px);
  max-height:100%;
}
<div class="wrap">
 <div id="header">Header<br>Header<br>Header<br>Header<br>Header<br></div>
 <div id="textarea-wrapper">
   <textarea id="text"></textarea>
 </div>
 <div id="footer">Footer<br>Footer<br>Footer<br>Footer<br></div>
</div> 

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

Having trouble with dragging a file from one box to another in HTML5. The functionality is not working

Encountering an issue where the image does not display in the left box after dropping it. Here is the sequence of events: Before dragging the image: https://i.sstatic.net/C6JSM.png After dragging the image, it fails to display: https://i.sstatic.net/7Du0 ...

Personalized animated Reactflow Connection Lines

My goal is to develop a personalized animated connection lines in reactflow, rather than using the default dashed line that appears when the animated: true prop is applied. I am aware that we can customize the styling by using the following code snippet: ...

What are the steps to transmit post data containing PHP source code with symbols such as (+, *, /, -) and save this information to a file using an AJAX request?

Currently, I am working on a web application that resembles w3schools' "Try it yourself!" feature. For now, I am focusing on the core functionality of the application without considering security measures. My Approach is : Getting user input throug ...

What could be causing the issue of not being able to load CSS files or images?

I'm currently in the process of learning how to develop websites, but I've encountered a stumbling block that I can't seem to overcome. I'm hoping someone here can help me out. I'm facing an issue where I am unable to link either a ...

Guide on storing images in a designated folder using CodeIgniter

My code is located in view/admin_view2.php <?php echo form_open_multipart('home_admin/createBerita'); ?> <div class="form-group" > <label class="control-label">upload foto</label> <inpu ...

Struggling to properly line up the baselines of navigation list items that are styled as circular elements using CSS

I have transformed my navigation menu into a series of CSS circles with text inside. The issue I am facing is that the text spills out unevenly based on the amount of content in each circle. To address this, I used a JavaScript solution to center-align the ...

Foundation Unveil Modal hidden from view

I'm currently integrating modals using Foundation 5 in a Rails application. The issue I'm facing is that the modal only works when the page is not scrolled down. If you scroll to the bottom of the page and try to activate the modal by clicking ...

Looking for a solution to dynamically fill a list in JQuery with data from a JSON file. Any suggestions for troubleshooting?

Currently, I am utilizing a JSON file to fetch Quiz questions. In my approach, each question is being stored in an array as an object. The structure of the question object includes 'text' (the actual question), 'choices' (an array of po ...

Learn how to retrieve images from the web API at 'https://jsonplaceholder.typicode.com/photos' and showcase them on a webpage using Angular10

Using the API "https://jsonplaceholder.typicode.com/photos", I have access to 5 properties: albumId: 1 id: 1 thumbnailUrl: "https://via.placeholder.com/150/92c952" title: "accusamus beatae ad facilis cum similique qui sunt" url: "https://via.placeh ...

utilize a variable to insert the image URL into CSS styling

When I retrieve a product image URL from my database, I apply CSS styling to it on the front-end page. However, I need to dynamically pass the product image URL into the CSS that specifies the background image... Here is my current CSS: .product-image .bg ...

The functionality of "Body Onload" for sending "ScrollHeight" is malfunctioning in Chrome and Safari

I came across an issue where the iframe_resize function in my code was not working as expected. After investigating further, I realized that the problem did not lie with the function itself. So, I decided to post a new question. Within my index.html file ...

Tips for making Google search results include query strings in the returned links

I need help figuring out how to make Google search results show a URL containing a query string. Here's an example from the project I am currently working on: Instead of this link, Google search returns: If anyone has any suggestions for fixing this ...

The title in my div class doesn't seem to be properly centered, even though I have set the margin to auto. What steps can I take to correct this issue?

My div is set to have a margin:auto, but the h1 inside is not centered as expected. I've tried various solutions, but none seem to work. Can someone please help me get it centered properly? body { background: #5D6D7E; color: wh ...

Positioning an image on the left side of a div within a flex container using

Here is the code I have: .usp-bar { display: flex; flex-wrap: wrap; background-color: #005932; color: #fff; font-weight: 700; padding: 10px 0; margin-top: 0; ju ...

What is the best way to position my two icons next to each other in the footer of my React application?

I'm struggling with styling the footer of my react portfolio project. I specifically want to include Github and LinkedIn icons side-by-side at the bottom of the screen, but currently, they are stacked vertically in the middle of the page with too much ...

"Efficiently showcasing images within percentage-based divs with responsive design

I've been struggling to figure this out. Is there a way to make the image element responsive when resizing the percentage div window? css div{ width:60%; height:400px; } div > img{ width:100%; height:100%; min-height:100%; ...

The CSS media query is failing to function as expected

My CSS code is as follows: @media screen and (max-width :300px) { .ui-tabs .ui-tabs-nav .ui-tabs-anchor { float: left; text-decoration: none; } } This means that I intend to modify the CSS when the screen size goes below 300px. I hav ...

Avoid stretching the div to the edge of the screen

In the table on my page, I have implemented a feature using CSS to display additional information in a popup div. This works well when there is limited text, but if there is extensive text in the table, it extends beyond the screen width and becomes diffic ...

What is the proper way to ensure a pull right display appears correctly?

This is the code I am currently using .tag-container.bottom-border.col-middle h1.text-center {{ tag.name }} button.btn.btn-follow.pull-right(ng-hide="hasFollowed" ng-click="tagArticles.followTag()") Follow I am trying to align the tag name in th ...

How to implement the @click event on a Bootstrap4 dropdown menu in a Nuxt.js project

I am working with a Bootstrap 4 dropdown that I want to customize by changing its button's background color when clicked. However, when I tried to add the click event, the dropdown menu no longer hides. Below is my code: //template <div class=" ...