Customizable form with dynamic content and interactive button within a set location

One distinct challenge not addressed in the similar inquiries below relates to a FORM component with both a variable segment and a fixed footer for submit buttons.

The objective is to present:

  • A header (a table set to 100% width including a logo and text): size should be minimal while displaying all content
  • A FORM structure (comprising two parts):
    • Fields housed within a div that expands to fill available space and scrolls if needed. (minimum size: one line of text)
    • Submit/Reset buttons placed in a table, always visible and never resized. Ideally, they remain at the bottom of the browser window except in extreme cases of window resizing.
  • It is essential that no content extend beyond the bottom of the browser window unless under very unusual circumstances.

    • Setting a fixed height is not an option, except when technically necessary (such as using 100% on a parent element like body or column). The heights of the header and footer must auto-adjust to utilize minimum space while showing all content. Should the user decrease the window width causing header/footer text to wrap onto additional lines, the height should adjust accordingly. Thus, percentages or viewport height are not suitable options due to their lack of adaptability to factors like zoom level or browser resizing.

I attempted the following layout:

<div id="column">
<div id="header>
  <table><tbody>
    <tr><td>LOGO</td><td>Some intro text on a few lines</td></tr>
  </tbody></table>
  <!-- optional error line of arbitrary length in case of failed form submission -->
</div>

<form>
  <div id="variable_scrollable_content">
  <!-- multiple field sets hosting various inputs (text, select, etc.) -->
  </div>

  <div id="footer">
  <table><tbody>
    <tr><td>Save button</td><td>Reset button</td></tr>
  </tbody></table>
  <!-- A few lines of text -->
  </div>
</form>
</div>

After reviewing similar questions (see list below), I could not find a solution accommodating the need for a scrollable section within a dynamic-sized FORM combined with a fixed footer.

I also explored https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox without success.

Attempts with flex classes applied to the header, variable_scrollable_content, and footer were unsuccessful. Including the entire form object in a flex class proved unproductive as well.

As the FORM's submit/reset buttons cannot be separated from the managed fields, a resolution remains elusive.

  • Header ought to remain anchored at the top of the browser window
  • Footer (housing form control buttons) should stay fixed at the bottom of the browser window ideally or position themselves after the last field if there is adequate space
  • Fields should reside within a container whose size adjusts dynamically to occupy space between the header and footer, capable of scrolling if content exceeds capacity

If the abridged code above proves insufficient, refer to the "real" source code here: https://github.com/finley/SystemImager/blob/initrd-from-imageserver-and-dont-package-initrd/webgui/edit_config.php The complete CSS stylesheet can be accessed here: https://github.com/finley/SystemImager/blob/initrd-from-imageserver-and-dont-package-initrd/webgui/css/screen.css

Similar Inquiries

In evaluating related queries listed below, it appears my specific issue centers around the interplay of the FORM element with the overall layout design:

  • Scrolling content between fixed header & footer with variable height
  • Content height expand between fixed header and fixed footer
  • Make a div fill the height of the remaining screen space

Original question found here: Variable Height Div Between Header and Footer

Answer №1

After some exploration, I have discovered the solution to the issue at hand. It appears that the problem stemmed from the FORM object causing interference with flex column children on different levels within the DOM tree.

The resolution was rather straightforward - by adjusting the placement of the FORM object so that it encompasses the entire flex column along with its content.

The updated code looks as follows:

<form>
<div id="column">

  <div id="header>
    <table><tbody>
      <tr><td>LOGO</td><td>Some intro text on a few lines</td></tr>
    </tbody></table>
    <!-- optional error line (arbitrary length) if previous form submission failed -->
  </div>

  <div id="variable_scrollable_content">
  <!-- multiple field sets hosting some input (text, select, ...) -->
  </div>

  <div id="footer">
  <table><tbody>
    <tr><td>Save button</td><td>Reset button</td></tr>
  </tbody></table>
  <!-- A few lines of text -->
  </div>
</div>
</form>

However, this adjustment alone proved insufficient as setting the flex column height to 100% did not produce the desired outcome, possibly due to the FORM object failing to propagate the height. The solution involved setting the height of the column using the vh (viewport height) unit.

Hence, I specified the height as 100vh. Unfortunately, there were some visual anomalies arising from border sizes and padding within parent and child objects. As a workaround, I adjusted the height to 96vh temporarily until I resolve the underlying border size and padding issues that caused the body to exceed 100vh.

<body style="height: 100%">
  <form>
  <div style="display: flex; flex-flow: column; height: 100vh;">
    <div id="header" style="flex: 0 0 auto;">foo bar</div>
    <div id="content" style="flex: 1 1 auto; overflow-y: scroll;">Input fields</div>
    <div id="footer" style="flex: 0 0 auto;">Control buttons</div>
  </div>
  </form>
</body>

The resulting structure exceeded 100vh in height, presenting two potential solutions:

  • Eliminate any border padding or similar tendencies from the parent object.
  • Adjust the column to an absolute position (0,0).

Answer №2

An alternative approach to creating a scrollable form within a flex container with a fixed footer containing control buttons is to place the form control buttons outside of the form.

Here's how the code would look:

<body style="height: 100%">
  <div style="display: flex; flex-flow: column; height: 100%;">
    <div id="header" style="flex: 0 0 auto;">foo bar</div>
    <div id="content" style="flex: 1 1 auto; overflow-y: scroll;">
        <form id="foobar">
          Input fields
        </form>
    </div>
    <div id="footer" style="flex: 0 0 auto;">
      <button form="foobar" type="submit" formmethod="POST">Submit</button>
      <button form="foobar" type="reset">Reset</button>
    </div>
  </div>
</body>

The benefit of this method is that it accommodates for parent margin borders and padding when setting the height to 100%, unlike using vh which is an absolute viewport size.

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

Manipulating SVG filter attributes with CSS: A comprehensive guide

In my quest to master CSS animation, I found myself needing to manipulate the values of SVG filter attributes. While attempting to reference a CSS variable within the specularConstant attribute, I encountered an error from the browser. Is it feasible to ...

Retrieving Hyperlinks from JavaScript Object for Integration with D3-Created Table

Issue: I'm facing a problem where the HTML link extracted from an Associative Array is treated as a string instead of being applied as a clickable link in the browser. For a detailed visual example and code snippet, visit: http://example.com/code Da ...

Employ a separate function to extract HTML content from a jQuery target in an AJAX response

Initially, the HTML div is empty upon loading the page. However, clicking a button triggers jQuery AJAX to load new HTML content into the div. $("#control-list a#ms").click(function(){ var postData = "actionrequest=ms"; $.ajax({url:"SSSutility.php ...

Clickable div containing a hyperlink

I need assistance with a clickable div that contains a link. Here is the setup: HTML: <div onClick="goToCat(2);" class="author-topics-block "> <a href="http://mywebsite/page/?cat=2">The woman in steel</a> </div> CSS: .author ...

Tips on making a progress bar with a reverse text color for the "completed" section

I've been tackling this issue for hours, but haven't found a working solution yet. The challenge is to create a progress bar with a dynamic width and a centered label that changes its text color between the progressed and unprogressed parts. Here ...

Is it possible to exclusively focus on the specified data attributes?

Is there a method to specifically target the 'data-season' attribute with the value "winter"? This is my HTML: <li data-season="summer">summer <ul class="groups"> <li data-item="beach">beach</li> <li data-item ...

Transform preexisting Vue UI library measurements into pixels

I was curious about converting all existing units (em / rem) to pixels. How can I easily convert the entire output units to px? Are there any tricks or methods available? Currently, I am utilizing Vuesax UI to create a plugin for various websites and temp ...

Setting the height of a child div: A step-by-step guide

Within a nested div with a height of 48px and positioned relatively, there is another child div also with a height of 48px. The goal is to set the maximum height of the child div to 80% and the minimum height to 40%. However, even after applying these sett ...

Create a hyperlink to the tabbed navigation menu

I want to create links to the tabbed menu for my website. The homepage has 4 categories: car, van, truck, and special, each of which leads to the portfolio page. The portfolio page includes a simple filtered tabbed menu structured like this: <ul id="f ...

How come the mouseover effect on the div remains even after the mouse has been removed?

How can I keep the original CSS class when the mouse moves away? function highlight( x, y) { var sel=document.getElementById(y); sel.style.borderBottom= "2px solid "+x; sel.style.opacity="1"; sel.style.transition="all eas ...

Inserting a line break in real-time within a JSX statement

Currently working on a React application that retrieves song lyrics from an API. The API provides me with a lyrics_body attribute as a string, which I use to showcase the lyrics on the webpage. However, when React renders it, the format is not ideal becau ...

I need to style a blockquote so that it floats to the right, but I also want it to be

I want to enhance the appearance of my blockquotes by giving them a different color background and ensuring they stand out from the regular text. Although using float:right helps achieve this effect, I prefer not to force the blockquote to the right side o ...

Handling the width and borders of CSS cells that are positioned outside of a table

Welcome! I recently created a simple gantt organizer as part of a demo. My goal was to make the main table scrollable while keeping certain columns "frozen" for easy visibility when navigating through the data. To achieve this, I followed some advice found ...

Converting CSS colors from RGBA to hexadecimal format: A step-by-step guide

Within my selenium code, I am faced with the challenge of verifying that the background color code is #192856. However, when obtaining the CSS property of the element, it returns the color in rgba format. How can I retrieve the values in hex format? quick ...

Issue with style display:none not functioning in IE8, IE9, and IE10 when in Compatibility View mode

I am facing an issue with two DIVs on my webpage. One of them is set to have display:none based on certain conditions. Surprisingly, it works perfectly fine on IE10, Firefox, and Chrome. However, the problem arises on IE8, IE9, and IE10 Compatibility Vie ...

An overflow occurs due to the grid column gap

After testing CSS display: grid, I noticed that the grid-column-gap: 10px; property is causing the parent container to break. This makes the green area in my code smaller than the grid area itself. It seems like box-sizing: border-box; doesn't have a ...

Deploying CSS/JS files in Magento 2 is a crucial

Hello, I recently set up magento2 with the sample data included. After attempting to deploy static css/JS using the command php bin/magento setup:static-content:deploy, I didn't receive any errors but the issue persists. Additionally, I am unable to l ...

Utilizing Multiple Components on a Single Page in React.js

I'm currently setting up a React main page that renders two separate components - Header and Test. render() { return ( <Header /> <Test /> ); } The Header component contains static content, while the ...

Troubleshooting: Ngx-Echarts Animation Issue at Startup

I've been working on integrating ngx echarts into my Angular app, but I'm facing an issue with the animation during the initial load of the chart. Take a look at this Stackblitz example where you can see that the bars render quickly on initial lo ...

`I'm having trouble with my PHP variables disappearing after submitting a form (resolved)`

I am new to learning about forms and PHP. Currently, I am experimenting with a simple HTML file from W3Schools that contains the following code: <html> <body> <form action="welcome.php" method="get"> Name: <input type="text" name="na ...