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

The jQuery UI accordion fails to function properly after refreshing the data

I am facing an issue with my HTML page where data is loaded dynamically into accordions. The accordion functionality is implemented inside a function, which is called at regular intervals to refresh the data. Initially, the accordion displays correctly, bu ...

issue with mark.js scrolling to selected sections

Our document searching functionality utilizes mark.js to highlight text and navigate to the results. You can see an example of this in action here. If you search for "Lorem ipsum" -> the highlighting works perfectly, but the navigation jumps to fragmen ...

Is there a method to modify the arrangement in which 3 specific HTML elements are displayed (i.e., their hierarchy in relation to one another)?

I have 3 "p" elements and I'm trying to find a way to change the order in which they load on the page using JS or CSS. Below is an example of what I've attempted so far. When you click on the first box labeled "about 1," it opens up and displays ...

What is the best way to show the totals on a calculator screen?

As part of my work, I created a calculator to help potential clients determine their potential savings. Everything seems to be working fine, except for the total fees not appearing for all the boxes. I believe I might be missing the correct process to add ...

What is the best way to contain the CSS for dynamically generated HTML within a div element without impacting other elements on the page?

I am currently facing a challenge where users can input any HTML into a text box, and I need to manipulate that HTML by identifying elements such as anchor tags or divs. To achieve this, I have created a hidden div and copied the pasted HTML into it using ...

PHP jQuery buttons for popovers

With a simple click of a button, I can generate 8 presentations and then edit each one individually by clicking on its respective name. Within this editing process, there is another form where I would like to include additional buttons that allow me to cus ...

Is it possible to send an email with an attachment that was generated as a blob within the browser?

Is there a way to attach a file created in the browser as a blob to an email, similar to embedding its direct path in the url for a local file? The file is generated as part of some javascript code that I am running. Thank you in advance! ...

Trouble with CSS Vertical Alignment: Solutions to Fix it

Link to a JSFiddle for reference: http://jsfiddle.net/STmwz/4/ Initially, there is only the top div displayed. Upon clicking the edit button, the JavaScript code replaces the top div with the bottom div. However, during this transition, there is a slight ...

Is it possible to display this code through printing rather than using an onclick event?

I have a puzzle website in the works where users select a puzzle to solve. I am looking for a way to display the puzzles directly on the website instead of using pop-up boxes. I am proficient in various coding languages, so any solution will work for me. ...

By including "on click" as a trigger, child nodes in the (_hyperscript) can be activated

Currently, my goal is to design a menu that keeps track of whether the user has expanded or collapsed a menu item and its sub-menu items. The issue I'm facing is that the "_"on click"" event gets "attached" to all child elements. I have sco ...

Button with small width containing an icon and text

I am trying to create a simple HTML button that has an icon on top and a description below it. <div class="mybtn"> <div><img src="someimage.png"></div> <div>Button description</div> </div> My question is, ...

Deactivate a button based on a comparison condition

How can I prevent a button from being clickable when a specific condition is met? I attempted to do it this way, but it seems to be ineffective: <button type="text" disabled="{{candidature.statusCandidature.libelle == 'En cours' }}" >edit ...

Setting the thumbnail image for an HTML5 video: A step-by-step guide

Is it possible to set a thumbnail image for an HTML5 video? I would like to display an image before the video starts playing. Here is my current code: <video width="470" height="255" controls> <source src="video.mp4" type="video/mp4"> ...

conceal elements created with JQuery within an AJAX function

Is it possible to use jQuery and the $.ajax() method to submit a form, displaying only the result while hiding other elements on the page? I am looking to add a conditional in the Ajax method that will show the result if successful, hiding certain elements ...

`In Firefox, perspective can lead to unexpected overflow errors.`

Having difficulties setting up a parallax effect using CSS perspective and translateZ. Encountering strange overflow errors specifically in Firefox. Check out the issue here When moving the mouse around, noticing that the background-image is getting crop ...

JavaScript and HTML - specify the location in the html document where the JavaScript script will be displayed

I'm a beginner when it comes to JavaScript. I am trying to make sure that my HTML page remains unchanged while JavaScript text is displayed in a specific location without refreshing the entire page. To trigger a JavaScript function via a button on a ...

Can anyone suggest a way to change the orientation of mapped items from column to row?

In my React app, I am creating a keyboard using the following component: Keypad.js const Keypad = () => { const letters = [ 'Q', 'W', 'E', 'R', 'T', ...

Changing the color of buttons within the anchor and menu-separator classes in WordPress

Hi everyone, I'm new to WordPress and need help changing a green button to blue. I have found the button in an anchor tag with the class "menu-separator." Is there a way for me to write custom CSS to change its color? Here is what I currently have: ...

Is there a way to prevent a web page from automatically refreshing using JavaScript?

I would like my webpage to automatically refresh at regular intervals. However, if a user remains inactive for more than 5 minutes, I want the refreshing to stop. There is an example of this on http://codepen.io/tetonhiker/pen/gLeRmw. Currently, the page ...

Activate Jquery to display the submenu when clicked and conceal any other open submenus at the same time

I'm trying to create a responsive menu with menus and submenus using JQuery. However, as a newbie to JQuery, I'm struggling to hide a previous submenu when displaying another one. Here's the CodePen link Below is the HTML code: <nav cl ...