Positioning a footer at the absolute bottom of a webpage

I am currently working with 2 divs that are absolutely positioned within a relative container. I intend to utilize JavaScript for toggling visibility.

.container {
  position:relative;
}

.section1 {
  position:absolute;
  top:0;
  left:0;
  right:0;
  bottom:0;
}

.section2 {
  position:absolute;
  top:0;
  left:0;
  right:0;
  bottom:0;
}

.section1 .div1 {
  background:green;
}

.section1 .div2 {
  background:purple;
}

.section1 .div3 {
  background:brown;
}

.section1 .div4 {
  background:grey;
}

.section2 .div1 {
  background:pink;
}

.section2 .div2 {
  background:gold;
}

.section2 .div3 {
  background:blue;
}

.section2 .div4 {
  background:orange;
}

.footer {
    background:lightblue;
    min-height:100vh;
}
<div class="container">

  <div class="section1">
    <div class="div1">
      This is Item 1
    </div>
    <div class="div2">
      This is Item 2
    </div>
    <div class="div3">
      This is Item 3
    </div>
    <div class="div4">
      This is Item 4
    </div>
  </div>
  
  <div class="section2">
    <div class="div1">
      This is Item 1
    </div>
    <div class="div2">
      This is Item 2
    </div>
    <div class="div3">
      This is Item 3
    </div>
    <div class="div4">
      This is Item 4
    </div>
  </div>

</div>

<div class="footer">
  Footer
</div>

The two sections work as expected, however, the footer is not displaying correctly. Should I consider adding a clear fix?

Answer №1

The footer currently has a min-height of 100vh. Perhaps this was intended for the container instead? Consider removing it from the footer and placing it in the container class.

Answer №2

To ensure your footer is properly positioned at the bottom of the page, you should consider applying a position property to it and removing any set height values.

If you want your footer to stick to the bottom, try adding the following CSS code:

.footer {
  background: lightblue;
  position:absolute;
  bottom:0;
  width:100%;
}

body{
  margin:0;
}

.container {
  position: relative;
margin:0;padding:0;
}

.section1 {
  position: absolute;
  top: 0;
  left: 0;
  width:100%;
}

.section2 {
  position: absolute;
  top: 0;
  left: 0;
    width:100%;
}

.section1 .div1 {
  background: green;
}

.section1 .div2 {
  background: purple;
}

.section1 .div3 {
  background: brown;
}

.section1 .div4 {
  background: grey;
}

.section2 .div1 {
  background: pink;
}

.section2 .div2 {
  background: gold;
}

.section2 .div3 {
  background: blue;
}

.section2 .div4 {
  background: orange;
}

.footer {
  background: lightblue;
  position:absolute;
  bottom:0;
  width:100%;
}
<div class="container">

  <div class="section1">
    <div class="div1">
      This is Item 1
    </div>
    <div class="div2">
      This is Item 2
    </div>
    <div class="div3">
      This is Item 3
    </div>
    <div class="div4">
      This is Item 4
    </div>
  </div>

  <div class="section2">
    <div class="div1">
      This is Item 1
    </div>
    <div class="div2">
      This is Item 2
    </div>
    <div class="div3">
      This is Item 3
    </div>
    <div class="div4">
      This is Item 4
    </div>
  </div>

</div>

<div class="footer">
  Footer
</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

Arrange the divs vertically by utilizing flexbox styling

My goal is to use flexbox to vertically align three div blocks. Even though I can successfully align them horizontally, I am facing issues with vertical alignment. What could be the mistake in my approach? .banner { padding- ...

Having trouble making the JavaScript mouseenter function work properly?

Hi there, I'm having trouble with this code and I can't figure out why it's not working. $('#thumbs > li').mouseenter(function() { $(this).find("div").fadeIn(); }).mouseleave(function(){ $(this).find("div").fadeOut(); ...

What is the process for creating a modal transition?

I am attempting to add animation to a modal using a transition effect. My goal is to open it slowly, either from the center of the screen or from the bottom. However, I am struggling to understand how this can be achieved... While searching on Google, I c ...

Preserving spacing using minimum widths

Looking for some help with a page layout issue. I have a header on my page with a title and menu. Currently, the header has a margin and a minimum width set to the width of the menu. However, when the user resizes the window and reaches the minimum width, ...

Can you modify the current HTML code of a Wix website?

I am currently developing a website using Wix and have encountered an issue with the page description. Despite editing it in Wix, the changes are not reflecting on the live site. Upon inspecting the source code in Chrome, I identified the problem lies wi ...

Need assistance with CSS layout: How to extend a div to the bottom of the page

I am currently working on a design layout that includes a 'header' section with a logo and links, as well as a content area that should extend to the bottom of the page. However, I am facing some challenges in achieving this. Initially, I enclos ...

Retrieve the browser version of a client using C# (When Internet Explorer Compatibility mode is activated)

Is there a way to retrieve the actual version of the client's browser from C# code? Using Request.Browser or HTTP_USER_AGENT provides details, but in Internet Explorer (IE), when compatibility mode is enabled, it always returns IE 7 regardless of the ...

Vue.js having compatibility issues with Semantic UI dropdown feature

I have recently started exploring Vue.js and I must say, I really enjoy using Semantic UI for my projects. In Semantic UI, dropdowns need to be initialized using the dropdown() function in semantic.js. This function generates a visually appealing HTML str ...

Tips for creating gaps between wells within a Bootstrap row

Utilizing bootstrap, I am aiming to position two wells side by side without them being squeezed right next to each other. However, I am encountering some issues with achieving this. Here's the code snippet I am currently using: <div class="contai ...

Utilizing JavaScript to Load and Showcase Images from a Temporary Image to imgsrc

How can I dynamically display images from the temporary image array 'tempimages' onto the 'img' element with the 'src' property? I have written a code that attempts to display temporary images from 'tempimages[]' on ...

Iconic Side Navigation with collapsed button malfunctioning due to negative positioning

I'm facing two issues with my webpage. First: I have three buttons on the right side of my page that are supposed to behave like the buttons on this example. However, when you scroll, you can see that their position is incorrectly displayed "outside" ...

JavaScript to toggle the visibility of elements when they move outside of a specified container

Check out this js+html/css project I worked on: http://jsfiddle.net/A1ex5andr/xpRrf/ It functions as intended - opening and closing with the use of .advSearch-btn to open/close, and .advSearch-control .canc to close. However, I am facing an issue where it ...

What is the most effective method for preserving RichText (WYSIWYG output)?

I am currently using a JavaScript-based rich text editor in my application. Could you suggest the most secure method to store the generated tags? My database is MySQL, and I have concerns about the safety of using mysql_real_escape_string($text);. ...

When you tap on the child element, ignore the parent element

Is there a way to make CSS understand that clicking on a child element within the parent should not be considered as clicking on the parent as well? Why not give it a try by clicking on one of the children inside the parent? .parent{ background: b ...

The functionality of the jQuery program is compromised when used on the Google Chrome browser

I just recently started diving into the world of Jquery, attempting to learn it from scratch. However, I have encountered an issue while trying to make my Jquery program run smoothly: Let's take a look at the CSS first: p { opacity: 0; } Now on ...

Mastering the Art of Line Breaks in WordPress

I am looking for a way to break a WordPress site title over two lines at a specific point in the text. Since the WordPress content filter 'wpautop' disables the ` ` tag (also known as ` ` or ` `), I'm wondering what the best alternative ...

Is jQuery Mobile Autocomplete's search feature activated after typing 3 letters?

Hello there, I am in the process of creating a website and have implemented an autocomplete field. However, I am facing an issue due to having over 1000 <li> elements within the <ul>, making it slow especially on mobile devices. I would like t ...

What causes jQuery's append function to trigger a redraw of my Div?

I have a unique function that incrementally increases the date by one day every second. Once the date matches specific dates, I aim to update my #newsDiv with extra text content. The #newsDiv will display all historical "news" and will be set to scroll to ...

How to save HTML content in a variable for future use in Next.js

When working with Next JS, my code resembles something like this: function Test() { return ( <section> <div>Test</div> </section> ); } Now, imagine that I want to have multiple entries here, gen ...

Error 404 - CSS file missing: encountering a 404 error while attempting to execute Flask code

Hello there! I'm still getting the hang of programming, especially when it comes to web development. Recently, I encountered an issue with my CSS file - whenever I link it to my HTML and run the Python code, I get an error saying that the CSS file can ...