Google Chrome - flexbox - container element

Please check out this code snippet in Chrome: codepen example

html:

<div class='flexbox'>
  <div class='static'>ddd
  </div>
  <div class='flex'>
    <div class='flex-child'>
      <div class='container'>
        *** lengthy text goes here *** ...</div>
    </div>
    <div class='flex-child'>hhh
    </div>
    <div class='flex-child'>hhh
    </div>
  </div>
  <div class='static'>ddd
  </div>
</div>

css:

html,body{
  margin:0;
  padding:0;
  overflow:hidden;
}
.flexbox{
  position:absolute;
  background:black;
  width:100%;
  height:100%;

  display: flex;
  flex-direction:column;
}

.flex{
  background:blue;
  flex:1;
  display:flex;
  position : relative;
}

.flex-child{
  background:red;
  width:100%;
  display:block;
  color:white;
  position : relative;
}

.static{
  background:transparent;
  width:100%;
  color:yellow;
}

.container{
  position : relative;
  background:magenta;
  height:100%;      
}

The example provided should be relatively easy to understand. The main issue is: How can the .container div be adjusted to accommodate any type of content without overlapping the footer.

Attempt to remove the background colors. The text in .container might visually intersect with the .static footer. How can this layout be organized so that the .content div and its content do not overlap the footer?

Edit:

The footer needs to stay at the bottom of the screen. No fixed sizes or dimensions should be specified in the CSS.

Please treat my question as a test, an experiment. I am striving for a flexible layout without explicitly setting sizes or dimensions, for instance, header height 50px. I desire the layout to be as generic as possible. Therefore, if you delete all the text from the .container in my original codepen and examine the .container height using developer tools, it will probably be 0, but ideally, it should match the height of its parent .flex-child. It may not comply with the standard practice, but how can this be achieved?

Edit 2: I have elaborated on my issue in another query alongside codepen and an image. Thank you for your input.

Thank you

Answer №1

Your specific requirements regarding the placement of the footer are somewhat unclear.

Solution 1.

The footer should be fixed at the bottom of the viewport, ensuring that the entire page fits within the viewport.

In this scenario, the content of the main element can vary in size, with a scrollbar appearing when the content exceeds the height of the element.

Check out the Codepen demo for Option 1

Solution 2.

The footer should be placed at the bottom of the page/document, which can have a variable height (but must meet a minimum height requirement equivalent to the viewport).

In this case, the content of the main element can expand freely, causing the page/document to adjust accordingly.

Take a look at the Codepen demo for Option 2

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

Where is the best place to insert Javascript code in an HTML file - the head or body section?

I am currently developing a search engine and have implemented code to automatically redirect users from HTTP to HTTPS when they visit my site. The only question I have is whether I should place this code in the head or body section of my webpage. if(wind ...

The cloned rows created with jQuery are failing to submit via the post method

Hello, I am currently working on a project in Django and could use some assistance with my JavaScript code. Specifically, I am trying to incorporate a button that adds new rows of inputs. The button does function properly as it clones the previous row usin ...

Creating a div that takes up 100% of its parent's height, regardless of the children's dimensions, in a sophisticated layout

My webpage layout is structured as follows: https://i.sstatic.net/5rdiw.png The left side, identified as D, functions perfectly. It contains a significant amount of content that scrolls correctly. Even as the content increases, the height stays at 100% o ...

How to adjust the size of a div based on its child content, including margins

I have encountered an issue with animating the height of a configurable content div, which typically contains paragraphs of text. Shown below is my animation (slowly paced), starting from a height of 0 and expanding to its calculated height based on its c ...

Sweetalert not functioning properly when deleting records from Datatable

I am currently working on a CRM script and encountering an issue. The customers are stored in a data table, and I am trying to implement a delete function with confirmation from both the database and the data table. I have written some code and placed it w ...

Is left padding appearing mysteriously (supernatural CSS phenomenon)?

While using the Firebug inspector tool, if you hover over #jimgMenu ul, you may notice that it has left padding without any corresponding CSS rule: Where is this mysterious left padding coming from? Why is the origin not visible? EDIT: If you navigate t ...

What is the best way to override @include within a CSS class?

Our team's application utilizes Bootstrap SASS for styling, but we have made certain customizations to the framework. The Bootstrap files are included in our project through a build process, making direct modifications impossible. When it comes to dr ...

Cannot modify CSS Position once it has been appended

I have a dilemma where I am appending code from one document to another. After the code is appended, I attempt to set the position of the newly added item using jQuery drag and drop functionality. The positions are stored in an array and then saved in a co ...

JavaScript Image Swap

I tried implementing this script but it didn't work for me. I'm not sure what to do next, so I'm reaching out for help. The script is at the top of the page, followed by a picture with an id that I'd like to change when a button below i ...

Attempting to make initials fade and slide out upon mouseover using jQuery

I've been experimenting with jQuery to create a unique effect where hovering over my initials in the header expands the containing div and reveals my full name letter by letter. However, I'm facing some challenges and could use some guidance on t ...

The navigation bar seems to have disappeared from the second page of the website

My navigation bar is working perfectly on my landing page, but when I copied and pasted it onto the second page, it's not showing up. I'm puzzled as to what could be going wrong, as I've checked and rechecked the code multiple times. I have ...

Align Divs Horizontally to Center

I'm trying to find a way to horizontally center multiple DIVs in a straight line. Here's how my code currently looks: HTML: <div id="circle"> <div id="circle1"></div> <div id="circle2"></div> </div> CSS ...

The controls for the HTML audio component are missing the download option on Safari

In my React application, I've declared an audio component with controls like the following: <audio controls> <source src={url} /> </audio> While this setup works perfectly in most browsers, it seems to have a bug when used in Safa ...

Display v-select options by clicking a button

I am trying to figure out a way to make the vuetify v-select component appear when I click on an icon button. The v-select should remain hidden when closed, only visible when triggered by clicking the button. It's like having the button toggle the vis ...

The button on my page refuses to align in the center, and I'm at a loss as

Struggling to center a button within my div, despite having all other content centered. Here is my code: .middle { width: 100%; height: auto; text-align: center; position: relative; ...

website with a horizontal scroll-bar

Looking to create a horizontal scrolling website where the divs float to the right without specifying the container's width, as it may vary on different pages. Any suggestions? ...

When it comes to Shopify Schema, the section settings are functional within the <style> tag, whereas the block settings do not seem to have the same

While working on updating a section with multiple blocks, I encountered an unusual issue. My goal was to incorporate a new block into an existing section. The schema has been set up correctly, and everything is functioning as anticipated. However, the prob ...

The resizing function on the droppable element is malfunctioning on Mozilla browsers

I've been working on making one div both droppable and resizable. Surprisingly, everything is functioning perfectly in Chrome but not in Firefox. If you'd like to see the issue for yourself, here is my jsFiddle demo that you can open in Firefox: ...

Tips for transitioning from custom CSS to Material UI's CSS in JS

I came across a project where someone implemented components with custom CSS. One interesting thing I noticed was a wrapper component, similar to Material UI's Container or just a simple div with applied styles. export const Container = styled.div` ...

Javascript - Button animation malfunctioning after first click

One issue I'm facing is with an animation that is triggered using the onmousedown event. Another function is supposed to stop the animation when onmouseup is detected. The problem arises after the first time it works correctly. Subsequent attempts to ...