Set the footer div to be positioned at the bottom within a table-cell that has a width of

In my layout, I have a container div with display: table, containing three inner divs with display: table-cell.

The two outer table-cells have a fixed width, while the inner table-cell has width: 100% to scale with the browser width.

My challenge is placing a footer div at the bottom of the middle cell using width: 100%, but it extends beyond the boundaries of the middle table-cell. How can I address this issue?

For reference, please see the example here: https://jsfiddle.net/9opnx9r8/

Below is the HTML code snippet:

html,
body {
  height: 100%;
}

.cell {
  display: table-cell;
  border: 1px solid red;
}

.cell1,
.cell3 {
  min-width: 150px;
}

.cell2 {
  width: 100%;
}

.text {
  border: 1px solid green;
  position: absolute;
  left: inherit;
  bottom: 0;
  width: 100%;
  height: 70px;
}
<div style="display:table; min-height: 100%;">
  <div class="cell cell1">
    <h1>C1</h1>
  </div>
  <div class="cell cell2">
    <h1>C2</h1>
    <ul>
      <li>List</li>
      <li>must</li>
      <li>stay</li>
      <li>top</li>
    </ul>
    <div class="text">FOOTER TEXT HERE</div>
  </div>
  <div class="cell cell3">
    <h1>C3</h1>
  </div>
</div>

Answer №1

To determine the containing block for absolutely positioned elements, look for the nearest positioned ancestor.

If there is no positioned ancestor to be found, then the containing block defaults to the viewport.

In order to designate an element as the containing block for the footer, make sure to include position: relative in its CSS properties.

html,body {
  height: 100%;
}

.cell {
  display: table-cell;
  border: 1px solid red;
}

.cell1, .cell3 {
  min-width: 150px;
}

.cell2 {
  width: 100%;
  position: relative; /* NEW */
}

.text {
  border: 1px solid green;
  position: absolute;
  left: inherit;
  bottom:0;
  width: 100%;
  height: 70px;
}
<div style="display:table; min-height: 100%;">
    <div class="cell cell1">
      <h1>C1</h1>
    </div>
    <div class="cell cell2">
      <h1>C2</h1>
      <ul>
        <li>List</li>
        <li>must</li>
        <li>stay</li>
        <li>top</li>
      </ul>
      <div class="text">FOOTER TEXT HERE</div>
    </div>
    <div class="cell cell3">
      <h1>C3</h1>
    </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

What is the process for obtaining the eq of a visible list using jQuery?

Is there a way to identify the index of the visible list item in jQuery and then save it into a variable? Consider the example slideshow below: Create a variable called currSlides. Save the index of the visible li into currSlides. The value of currSlid ...

Is there a way to display Bootstrap 4 progress bars next to each other in two distinct columns within a single container?

I am struggling with controlling the positioning of Bootstrap 4 progress bars. It seems that Bootstrap's progress bars are based on Flexbox components, which is causing confusion for me. I have provided an image showcasing my issue here Within my cur ...

Tips on finding the key associated with a specific value

When a form is submitted, one of the fields being sent is an ID number instead of the name for easier processing by the server. For example: HTML dropdown select <select ng-model="myColor" class="form-control" ng-options = "color.ID as color.color ...

${IDHERE} element's text color not changing when tab is switched

One dilemma I encountered involves displaying a percentage on a webpage with 2 tabs. The percentage is originally shown on the tab that is open when the page loads. The JavaScript code I used is quite straightforward: adaPercentColor(percent, ada) { ...

Strange border adjustment for customized-height input[type=button] in Internet Explorer 6 and Firefox 3

Upon my discovery, I encountered a peculiar issue in IE6/FF3 when trying to set a custom height (even if it matches the default) on a button. The following code illustrates that although both buttons have the same height, their padding differs inexplicably ...

Can the manifest.json file be edited dynamically?

I'm in the process of developing a React PWA and I'm exploring the possibility of dynamically adding icon URLs to the manifest.json file. My aim is to display a generic app icon until the user logs in. Once logged in, I plan to fetch a new icon f ...

.bootstrapMaterialDatePicker does not work within Codeigniter version 3

I am experiencing an issue with my form that has two date fields stored as varchar <div class="row clearfix"> <div class="col-lg-2 col-md-2 col-sm-4 col-xs-5 form-control-label"> <label for="ar ...

An image tag acts in a similar way to a div element

I'm a bit confused about how the picture tag works in relation to an img tag when its parent has 'display: flex' applied. When I set width: 50% on the img tag, it doesn't make the image 50% of the div but rather 50% of the picture eleme ...

The justify-content-center class in the latest version of Bootstrap (v4.5) appears to be malfunction

I'm currently working on creating a responsive contact section for a website I'm developing for a small local company. Unfortunately, the icons in their container are not being centered despite using the justify-content-center class from Bootstra ...

What is the process for altering the active color of a materialize icon?

Currently working on a web application for my school project and incorporating the Materialize framework. However, I'm having trouble modifying the default teal color of the active icon. https://i.sstatic.net/9eEfM.jpg ...

Learn how to transform the html:options collection into html:optionsCollection

What is the best method to transform this code snippet: <html:options collection='catList' property='catId' labelProperty='catName'> using the <html:optionsCollection> tag? ...

Scrollable content below the div

I have encountered an issue where a div is positioned above another div, and when I scroll the upper div to the bottom, it ends up scrolling the entire body. To better illustrate this problem, I have created a demo on JSFiddle: http://jsfiddle.net/2Ydr4/ ...

What is one way to prevent a transformed element from being clipped by overflow-auto?

For my friend's personal site, I am using Bootstrap 4 to create a gallery within a modal. I have managed to make the images expand on hover, but I am facing an issue where the images get cut off at the edges of the modal when I set the overflow to aut ...

What is causing my button to act in this way?

Initially, the website redirects to an undefined URL and then to test.com. I am looking for a way to implement a redirection sequence from to and finally to <head> <script type="text/javascript"> <!-- function popup(url ...

Syntax Error: An unexpected token was found on the first line

I need help with parsing a text file that stores details in a specific format: Hayden:Australia:200:7800:45 Lara:West Indies:204:10800:47 Gilchrist:Australia:100:12800:45 In my PHP code, I'm attempting the following: <?php $fields = array("n ...

Ways to link two PHP scripts

My code snippet below aims to select a location from a dropdown menu and generate a pie chart based on data fetched from a PostgreSQL database. However, I am facing an issue where the pie chart displays all column values instead of only the selected locati ...

What is the best way to incorporate CSS from node_modules into Vite for production?

I have a TypeScript web application where I need to include CSS files from NPM dependencies in index.html. Here is an example of how it is done: <link rel="stylesheet" type="text/css" href="./node_modules/notyf/notyf.min.css&quo ...

Refreshing SQL Server data using an HTML form

In the table below: <table id="skuTable" role="grid"> <thead> <th class="skuRow">Order</th> <th>Fab. Date</th> <th class="skuRow">Norder</th> <th>Color</th> ...

The latest div I inserted is not aligning to the bottom of the page

I'm facing an issue with my webpage design. I recently added a new div for the footer wrapper (class = main_foot), but it's stuck in the top left corner. Objective: Move the div beneath the div class="main_content" I have verified ...

Positioning of Buttons in Bootstrap 4 Forms

Hey there, I'm encountering an issue with the placement of my button on my website <form id="filter_view" method="POST"> {% csrf_token %} <div class="form-row"> <div class="form-group col-md-1"> <label for="sel ...