How the footer behaves when the window is resized in CSS

After following the pointers I found in this resource, I successfully created a sticky footer. However, my goal now is to set the minimum window resizing limit to 700 pixels.

The issue arises when I resize the window and it falls below 700 pixels - there is an empty white space next to the footer, causing it not to cover the entire screen.

I'm a bit baffled as to what could be causing this problem. Here's the link to my example on jsBin:

`https://output.jsbin.com/gawidovijo`

Your assistance is greatly appreciated.

Answer №1

Start by adding position: relative; to the body element and switch margin: 0 0 100px; to padding: 0 0 100px;

It's important for the footer to have a relatively positioned parent in order to be positioned correctly. If not, it will position itself relative to the html element, which may cause unexpected placement. When using absolute positioning, make sure the parent is relatively positioned to define where the absolutely positioned element should be placed within. Since you are setting the max-width of your page on body, it is logical to position the footer relative to the body.

After making this adjustment, the footer will align with the body, ensuring that the bottom margin of the body appears below the footer. To display the footer within the designated space of 100px, change the method from margin to padding so the footer can be positioned accordingly.

Answer №2

Hey there Slashy,

I took a look at the page in Firefox, Chrome, and even IE11 on Windows 7, but I couldn't find the white space you mentioned. It might be worth trying to clear your browser cache to see if that helps.

Here are a few other things to keep in mind:

  • When using position: absolute;, remember that it is relative to the parent container. You may want to consider using position: fixed; instead, which uses the browser window as the reference point.
  • Try using padding-bottom on the body rather than margin-bottom.
  • Consider including box-sizing: border-box; in your CSS to ensure that padding doesn't add to the total width when set to 100%.

Remember, when absolutely positioning elements, you need to define the parent's position if you want the child element to be positioned relative to it. Here's an example of positioning a div at the top right corner:

<body>
  <div class="parent">
    <div class="child">This content goes in the top right</div>
    <p>Parent content here</p>
  </div>
</body>

And the corresponding CSS:

.parent {
  position: relative;
}
.child {
  position: absolute;
  top: 0px;
  right: 0px;
}

If you don't specify position: relative; on the parent element, the absolutely positioned child will be based on the body.

Absolutely positioning elements can be tricky at first, but I hope this explanation clears things up for you!

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

The complexities of stopPropagation() causing further confusion

I have encountered an issue with my code. It currently allows a dropdown functionality for a <ul> element, but when a child <li> is clicked, it also closes other menus of the same type. To fix this, I used an if clause to check if the clicked ...

Customizing the language parameter for the apply button script on LinkedIn

Our company's website features the AWLI button which allows users to apply for jobs using their LinkedIn profile. <div name="widget-holder"> <script type="text/javascript" src="https://www.linkedin.com/mj ...

Using ng-class directive with condition in AngularJS

Here is a unique pop-up that allows users to encode item information. https://i.sstatic.net/sn9QZ.png I need to implement a feature where, if both the Foreign Currency and Conversion Rate fields have values, the Amount should be calculated by multiplying ...

The functionality of the Bootstrap carousel is not functioning properly in the Firefox browser

I attempted to customize the bootstrap carousel in order to create a simple content slider. After reviewing two events in the bootstrap documentation and utilizing animate.css for animation, I found that Chrome and Internet Explorer displayed the animation ...

Total Output Calculation

In my latest coding project, I have crafted a unique algorithm to calculate exam scores with the inclusion of interactive buttons! function incorrectResponse() { var calc = 0; var calc2 = 1; var divElement = document.createElement("div"); divEle ...

When it comes to using brackets and HTML, I keep receiving an error message indicating that there is no index file

I'm having trouble with this code - it works fine in Code Academy, but I am new to HTML and trying to practice outside of the platform. Every time I try to live preview in Brackets, I get an error message saying "make sure there is an html file or tha ...

Exploring Zend Framework's headLink() helper with HTML5

I have set the doctype to HTML 5 by using the following code: $view->doctype('HTML5'); Next, I added a stylesheet in this manner: $view->headLink()->appendStylesheet($view->baseUrl().'/css/reset.css'); This code results ...

Adjust the size of the sliding tool with images of varying dimensions

My mobile-first slider features three different types of images: tall, horizontally long, and square. I want the size of the slider to be determined by the horizontally long image and then scale and center the other images to fit its size. To achieve this, ...

Calculating the sum of numbers within a PHP Foreach loop

I'm looking to calculate the total sum of individual records within a foreach loop. My table structure is as follows: <table> <tr> <th>Person Name</th> <th>Balances</th> <th>Total</th> & ...

Duplicate multiple "li" elements using jQuery and place them in a designated position within the ul element, rather than at the end

I am currently working on developing a dynamic pagination bar. This pagination bar will dynamically clone the "li" elements based on a number received from an external webservice. Here is the structure of my pagination element: <ul class="pagination"& ...

Enhancing spacing in Bootstrap 5 with additional spacers

Looking to enhance the spacers in Bootstrap 5 by incorporating it into Sass and customizing the variables. I'm aiming to avoid redundantly defining Bootstrap's spacer options, which are as follows: $spacers: ( 0: 0, 1: $spacer * .25, 2: $s ...

Enhancing the appearance of forms on Wordpress using ninja forms styling techniques

Seeking assistance in styling a form. After attempting CSS modifications, the form still lacks a background color. Can anyone provide guidance? #nf-form-8-cont { background-color: rgb(214, 214, 194,0.5); padding: 15px; box-shadow: 0px 3p ...

How to center align your application in the desktop using Ionic framework

Query: How can I ensure that my ionic mobile application renders in the center of the screen when viewed on a desktop browser? Attempt 1: I experimented with using a wrapper div with a fixed width, such as max-width:732px; and margin: 0 auto;, however Ion ...

The JQuery.hover() function is experiencing issues with detecting hover events while moving the mouse over

While attempting to enhance the functionality of hovering over a 2048 tile, I encountered an issue. Each tile with a value of n is assigned a class 'tile-n'. Specifically for the basic 'tile-2' tile, I have written hover functionality ...

Is it necessary to properly close meta and link tags in HTML documents?

As I inspected someone's HTML, I noticed that they didn't close the meta and link tags in the head section. Surprisingly, the code still worked perfectly fine; does this mean closing these tags is purely optional? I always believed that leaving ...

What is the best way to design a cell that overlaps with another?

I'm trying to figure out how to make a cell that spans the full width of the existing column and sits on top of the nearest cell. This is part of an effort to create a percentage graph. For example: https://i.sstatic.net/XZahG.png I've experim ...

Experiencing an issue with the left side menu bar in Bootstrap, looking to incorporate additional sub menu items

<li class="drop-menu-tab"> <a class="dropmenu" ><i class="icon-folder-close-alt"></i><span> Employee</span></a> <ul> <li><a class="submenu&q ...

Animating or transitioning CSS keyframes to an inline value when the page is initially loaded

In my current project, I am working on creating HTML and CSS-based bar representations of percentage values. The structure of the code is as follows: Using HTML: <div class="chart"> <div class="bar" style="width:43%"></div> </div&g ...

Unable to display PNG file on HTML document

Hi there, I'm having a bit of trouble adding a logo to my website. Initially, I had a sample logo that worked perfectly fine. Here's the code snippet: <a class="navbar-brand d-flex align-items-center" href="/"> <a ...

Eliminate unnecessary scrollbar from fancybox iframe

I am trying to display content in an iframe using Fancybox, but I am encountering an issue. Despite all the content being contained within the iframe, horizontal and vertical scroll bars are appearing. When inspecting the element in Firefox, I noticed th ...