The alignment of the footer component

Hey there! I've created a fiddle to demonstrate the issue I'm facing: https://jsfiddle.net/8a1qgodv/

In my design, the page-footer element is positioned absolutely at the bottom with 0px. However, when the height of the device is less than 730px, the footer ends up covering the page-body element.

I experimented without using absolute positioning, but then on a Galaxy S5 device, the page-footer doesn't stick to the bottom properly. There's always a small white space (around 20px) between the footer and the bottom edge.

Could you please share some tips or hints on how I can resolve this dilemma?

This is how the HTML structure looks like:

<div class="site-wrapper">
        <div class="container">
            <div class="page-header">
                <img class="img-responsive" src="http://www.smoshmosh.com/images/startseite_logo.png"/>
            </div>
            <div class="page-body indexPageBody">
                <img class="img-responsive" src="http://www.smoshmosh.com/images/startseite_content.png"/>
                <div class="startButton">
                    <a id="startButton" href="dummyUrl"><img id="startButtonImg" class="img-responsive" src="http://www.smoshmosh.com/images/start_button.gif"/></a>
                </div>
            </div>
            <div class="page-footer">
                <img class="img-responsive" id="startseiteFooter" src="http://www.smoshmosh.com/images/startseite_footer.png"/>
                <button id="audioToggleButton" class="startAudio"><img id="musicImage" class="img-responsive" src="http://www.smoshmosh.com/images/music_on.png"/></button>
            </div>
        </div>
    </div>

Answer №1

In order to keep the footer at the bottom of the page, you need to adjust the CSS in the following way:

.page-footer {
    max-width: 500px;
    /*position: absolute;*/ // If you were using absolute positioning, remove it 
    bottom: 0;
}

Make sure to assign a specific height to each 'div' to prevent them from overlapping.

For reference, here's an example: https://jsfiddle.net/8a1qgodv/2/

Answer №2

Wow, this problem is a breeze to solve.

An element with absolute positioning relies heavily on the positioning of its nearest parent element that has a non-static position.

To fix the issue, you can add the following CSS rule:

.site-wrapper {
    position:relative;
}

Check out this working fiddle for reference!

I recommend reading Mr Alien's response on the SO Question. Pay close attention to Demo 3 & 4.

This provides an excellent demonstration and explanation of how absolute positioning works.

UPDATE:

Furthermore, in order to accommodate the absolute positioned footer, make sure to create padding at the bottom of the site-wrapper like so:

.site-wrapper {
    position:relative;
    padding-bottom: 230px;
}

Here's another working example to review.

Answer №3

You have the option of setting a flexible height for it.

.wrapper {
  height: auto;
}

header {
  height: 10%;
  background-color: #3498db;
}

.content {
  height: 80%;
}

footer {
  height: 10%;
  background-color: #3498db;
}
<div class=wrapper>
  <header></header>
  <div class="content"></div>
  <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

Implement Bootstrap and Jquery in Laravel Jetstream setup

I added Jetstream and Livewire to my Laravel 8 project successfully. Now I am trying to include JQuery and Bootstrap in my project but facing some issues. Can anyone help me with this? UPDATE: I managed to figure out how to include Bootstrap, but I'm ...

Using javascript to quickly change the background to a transparent color

I am in the process of designing a header for my website and I would like to make the background transparent automatically when the page loads using JavaScript. So far, I have attempted several methods but none seem to be working as desired. The CSS styles ...

Can you use both HTML and JSON in ROR?

The scaffolding process generates controllers that include Create/Update methods. These methods are responsible for rendering HTML as well as JSON data. While I am familiar with HTML, I have limited knowledge about JSON. Should JSON be included in this cod ...

How to Generate a Table of Contents in HTML with JavaScript and jQuery

Looking to generate a table of contents in HTML using JavaScript and jQuery. The structure of my HTML headings is as follows: <section id="id1"> .... <section class="sidebar"> .... </section> <section id="id2"> ... <section id=" ...

Troubleshooting Material-UI Menus

I need the menu to adjust its height dynamically as the content of the page increases vertically. Even though I have applied "height:100%" in the styles, it doesn't seem to work. Can anyone assist with this issue? Here is the code snippet: import R ...

Directing a webpage to a particular moment within that page

Is it possible to automatically redirect users to a new page at a specific time? I would like visitors to be redirected to a new site starting from 12:00AM on December 31st, without allowing them to access the current site after that time. Is there a way ...

Guide to making a for loop using CSS custom properties and conic gradient in SCSS

Attempting to devise a for loop that will create this format for enhancing a progress bar style: progress[value="1"]::-webkit-progress-bar { background: conic-gradient( var(--progress-color) 0% 1%, var(--rest-col ...

Is there a way to align the arrow on the pills to the right center of the lengthy text?

I am struggling to align a pill on the right side of a header with long text using CSS. I need the pill to be centered at the right area with multiple lines of text. Can someone guide me on how to achieve this? Any assistance is appreciated. .c-cta-box- ...

Explaining the functionality of jQuery validation code

While exploring online tutorials, I stumbled upon a fascinating guide that makes use of jQuery and a validation plugin to validate form input. You can view the live example here: http://jsfiddle.net/nK7Pw/. Everything seems to be working perfectly, but o ...

Displaying a message within a picture

Is there a way to display the unread message count as text on my PNG image? You can find the image at header: span Messages =image_tag "login_icon6.png", class: 'img4' Unread count code: = current_user.mailbox.inbox(:unread =& ...

Creating a polished and stylish centered responsive image with Bootstrap 3

I am facing an issue with centering a styled responsive image on my website. Upon debugging, I discovered that the class "portimage" is causing the responsiveness to break. My requirement is to ensure that the images do not exceed 700px in size and have a ...

Utilize Bootstrap 4's d-print classes to style your form

After creating a form that allows users to submit online or print and mail, I encountered an issue with the printing functionality. When using a simple JavaScript print command and applying the .d-print-none class to hide all elements except the form for p ...

How can I include a script in a div using Javascript or Jquery?

I am facing a challenge where I need to incorporate a piece of javascript (Linkedin share button) into a specific div, but unfortunately, direct access to the DOM is not an option. However, using Javascript/jQuery to manipulate the DOM opens up possibiliti ...

Having an issue with retrieving value from a textfield in JavaScript

<input id="checkOldPassword" type="button" title="Check New Password" value="Check New Password" onclick="checkPassword()" /> <input id="newPassword" type="text" maxlength="8" min="8" /> <script language="javascript"> function checkPassw ...

the drawer conceals the paper

I am having an issue with my drawer overlapping the content on the page. I would like it to be aligned to the left without covering any other elements. This is my first time working with material-ui, so if anyone could help explain how to fix this, I wou ...

Merging Angular with jQuery: Organizing jQuery into a distinct file leads to the error message 'Property 'top' cannot be read because it is undefined.'

My project is based on AngularJS, and I've been trying to incorporate a jQuery code for a sticky sidebar feature. Strangely enough, when I tested my code on Plunkr, it works perfectly fine. However, when I try to implement it in my actual project, it ...

Selecting options in combobox for each row in a table using Angular 2 programmatically

I am currently working on an Angular 2 application using TypeScript. In one of the tables within the application, there is a select control in one of the columns. The contents of this select control are bound to another string array. <table ngContr ...

The design template is failing to be implemented on my personal server utilizing node.js

I've encountered an issue while developing the signup page on my local server using Bootstrap 4. The CSS is not getting applied properly when I run it locally, although it displays correctly in the browser. Can someone explain why this is happening? ...

Position the typography component to the right side

Is there a way to align two typography components on the same line, with one aligned to the left and the other to the right? I'm currently using this code but the components are aligned next to each other on the left side. const customStyles = makeSt ...

tips on displaying textbox content on a php webpage

I have a piece of code where, when text is entered into a textbox and the add attribute button is clicked, the entered value is displayed on the page twice. One appears in the first row of a table, and the other appears in the first row of a second table. ...