Inserting content at the footer of the webpage

I managed to center 2 divs using the power of flex, and now I want to introduce a third div at the bottom of the page, just like in the image below:

https://i.sstatic.net/pQleWm.jpg

(I need the first two divs to stay centered based on their parent element without being affected by the third div.)

I attempted to achieve this, but unfortunately, the third div kept getting pushed off-screen. I can't reduce the height of #centerWrapper below 100% either because then the alignment of the first two divs would be compromised.

Check out the JSFiddle here

*,
*:before,
*:after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
html,
body,
#parent {
  width: 100%;
  height: 100%;
}
#centerWrapper {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
#centerWrapper * {
  width: 100px;
  height: 100px;
}
#firstChild {
  background-color: brown;
}
#secondChild {
  background-color: lightblue;
}
#thirdChild {
  background-color: greenyellow;
}
<div id="parent">
  <div id="centerWrapper">
    <div id="firstChild"></div>
    <div id="secondChild"></div>
  </div>
  <div id="thirdChild"></div>
</div>

Answer №1

MODIFICATION

To maintain the specific positions of both blocks without relying on flexbox flexibility, consider using the position property for better control. Apply the following ruleset to the #centerWrapper:

  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);

To keep #thirdChild at the bottom of the viewport, include these styles:

  position: absolute;
  bottom: 0;

Turn #parent into a flex container for both #centerWrapper and #thirdChild.

SNIPPET

*,
*:before,
*:after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
html,
body {
  width: 100%;
  height: 100%;
}
#parent {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: center;
  background: yellow;
  overflow-y: visible;
}
#centerWrapper {
  width: 100px;
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
#centerWrapper * {
  min-width: 100px;
  min-height: 100px;
}
#firstChild {
  background-color: brown;
}
#secondChild {
  background-color: lightblue;
}
#thirdChild {
  min-width: 100px;
  min-height: 100px;
  background-color: greenyellow;
  position: absolute;
  bottom:0;
}
<div id="parent">
  <div id="centerWrapper">
    <div id="firstChild"></div>
    <div id="secondChild"></div>
  </div>
  <div id="thirdChild"></div>
</div>

Answer №2

Is it possible to utilize position: absolute on the thirdChild element? Here is an example code snippet: https://jsfiddle.net/7qa7cd20/1/

*,
*:before,
*:after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body,
#parent {
    width: 100%;
    height: 100%;
    position: relative;
}

#centerWrapper {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

#centerWrapper * {
    width: 100px;
    height: 100px;
}

#firstChild {
    background-color: brown;
}

#secondChild {
    background-color: lightblue;
}

#thirdChild {
    background-color: greenyellow;
    position: absolute;
    bottom: 0;
    height: 100px;
    width: 100px;
    left: 50%;
    transform: translateX(-50%);
}
<div id="parent">
    <div id="centerWrapper">
       <div id="firstChild"></div>
        <div id="secondChild"></div>
    </div>
    <div id="thirdChild"></div>
</div>

Answer №3

Your third child element is currently lacking height and width attributes, but you can easily center it by adding margin: auto;. I've set the div to 100x100 for visibility as well.

Check out the code here!

*,
*:before,
*:after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body,
#parent {
    width: 100%;
    height: 100%;
}

#centerWrapper {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

#centerWrapper * {
    width: 100px;
    height: 100px;
}

#firstChild {
    background-color: brown;
}

#secondChild {
    background-color: lightblue;
}

#thirdChild {
    background-color: green;
    height: 100px;
    width: 100px;
    margin: auto;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
}

#parent {
    position: relative;
}
<div id="parent">
    <div id="centerWrapper">
        <div id="firstChild"></div>
        <div id="secondChild"></div>
    </div>
    <div id="thirdChild"></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

Exploring html select and input elements in a loop

Currently, I am in the process of developing an application that calculates the total price of selected items based on user input. Each row consists of two dropdown menus (ID/item) and a quantity input field. Additionally, users have the option to add rows ...

Tips for concealing v-text-field entered date symbol

I am currently incorporating v-text-field to enable date inputs using the following code snippet <v-text-field label="Date" type="date"></v-text-field> By doing so, a text box with a calendar UI is generated (which allows ...

Tips for accessing webpage data using pandas

My attempt to extract data from a table on the webpage is proving challenging. The code I am using is as follows: import pandas as pd url="https://datahub.io/sports-data/german-bundesliga" pd.read_html(url)[2] Despite this, the code successfu ...

Changing results in a 1px movement of the image

Despite referencing this specific discussion thread, I still couldn't resolve the issue in my case (unless I placed the suggested code incorrectly). Essentially, when hovering over a link in Firefox, some images underneath shift by 1px (not all of th ...

Customize hover effects for MuiCheckbox

For some reason, my checkboxes are displaying a circle on hover that I want to remove. https://i.sstatic.net/62TLL.png I attempted to make overrides in MuiTheme: export const MUI_THEME = createMuiTheme({ overrides: { MuiCheckbox: { root: { ...

Is it possible to include all the information in a form submission, not just the inputs?

I have a problem with submitting the form and accessing all the variables I need. When I check the $_POST variable, I only see the values of the form inputs. Is there a way to also send other variables like the content of multiplicator1? How can I achiev ...

Firefox failing to display fonts from Google Font API

The landing page our company outsourced does not display the Lato font in Firefox, resorting to a different option instead. We have received a stylesheet from fonts.googleapis.com that includes the following: @font-face { font-family: 'Lato'; ...

Utilizing Angular to link input and button elements together

While going through the tutorial Tour of Heroes, I encountered a section about adding a new hero. The tutorial suggests using an input element paired with an add button. Insert the following code into the HeroesComponent template, after the heading: & ...

Load the jQuery script only in the absence of cookies

Hey there! I have a cool fade out effect on a website I'm working on. When you go to the site, a div containing the title of the site appears and then fades away after a while. It's pretty simple yet effective. <div class="loader"><h1&g ...

Ways to remove the extra space above and below text within a td element

My goal is to make the background change when a user hovers over the td element. The current behavior of my code can be seen in the image below: I am working to eliminate the white space so that the gradient fills the entire td/cell. The following code s ...

BOOTSTRAP Issue: The sticky footer in the template is not staying sticky

I am at the point where I am tempted to open my window and throw my computer out. I followed a tutorial on Bootstrap for the footer template. Everything looks good, but when my text extends beyond one page, the footer remains stuck in place and does not m ...

Angula 5 presents a glitch in its functionality where the on click events fail

I have successfully replicated a screenshot in HTML/CSS. You can view the screenshot here: https://i.stack.imgur.com/9ay9W.jpg To demonstrate the functionality of the screenshot, I created a fiddle. In this fiddle, clicking on the "items waiting" text wil ...

Breaking the website with an HTML comment

Upon clicking a link to another page, I encountered the error message "Failed to execute 'insertBefore' on 'Node." Here is the code snippet that was causing the issue: <template name="reminderPage"> <a href="/newRemind">New! ...

The color of a Three.js plane appears more intense with the addition of lights

import * as THREE from 'three'; import {OrbitControls} from 'three/examples/jsm/controls/OrbitControls.js'; import * as dat from 'dat.gui'; const renderer = new THREE.WebGL1Renderer(); renderer.shadowMap.enabled = true re ...

The issue of CSS3 list navigation not aligning to the left side

While following a tutorial on tuts+ premium, I encountered an issue when the series creator failed to include an exercise file. Despite copying everything from the tutorial video into a CSS document accurately, the CSS list items simply would not float lef ...

I need help fixing the alignment of the lengthmenu and export buttons in Bootstrap Datatables Javascript. They are too close together and I want to create a line break between

I'm currently working on a searchable table that requires users to export their results and choose the number of entries they want to see. However, everything appears too congested. I am looking to create some spacing by adding line breaks, paragraphs ...

Unlocking the Power of Dynamic Title Text in Your Content

Recently, I came across a tooltip code on Stack Overflow which I have been using. The issue I am facing is that the text in the title section is hardcoded and I need to customize it for different labels. How can I modify the code to make it flexible enough ...

Guide to adding a tag in front of a text in HTML with Python

Searching for all the text within the html document and wishing to incorporate a span tag that contains additional information about each text as shown below def recursiveChildren(x): if "childGenerator" in dir(x): for child in x.childGenerator( ...

Array containing HTML code for Ionic framework

Just starting out with Ionic/Angular and I have a question. How can I display an array containing HTML content? { "code" : "06", "descr" : "Some text:</br>Other text.<br/>Other text</br>Other text." } When I try to print it, the HTML ta ...

Difficulty in aligning Grid elements in Material UI version 5

Strange enough, the MUI5 Grid is displaying unexpected spacing behavior. Instead of providing proper spacing between items and containers, it seems to be causing them to overlap. To see a live example, visit: https://codesandbox.io/s/green-worker-z44vds? ...