Tips for positioning a div element at the bottom of a webpage

I am currently working on placing this banner ad at the bottom of the page. I want the image to be positioned within the banner div without overlapping the div above it.

.banner {
    width: 100%;
}

.banner img {
    width: 100%;
    max-height: 140px;
    z-index: 99999999999;
    position: fixed;
    bottom: 0;
}
        <div class="banner">
            <img src="http://machahid.info/wp-content/uploads/2016/12/pubmobile.gif" alt="ads">
        </div>

An image illustrating the problem can be found here: https://i.sstatic.net/zrHcQ.jpg

Thank you, everyone.

Answer №1

To ensure enough space at the bottom of your page for the ad, consider adding a padding-bottom or margin-bottom of 140px to the container element, such as the body or a div. This will provide a designated area for the ad to be placed.

Answer №2

To ensure elements remain within their parent container, avoid using position: fixed. Instead, apply position: fixed and bottom: 0 directly to the .banner class:

.banner {
    width: 100%;
    position: fixed;
    bottom: 0;
}

.banner img {
    width: 100%;
    max-height: 140px;
    z-index: 99999999999;
}

By following this approach, the entire banner will stay fixed at the bottom while the image remains contained within its boundaries :)

I've put together a demonstration on this fiddle.

I trust this solution proves to be helpful!

Answer №3

Avoid using position: fixed as it can lead to performance issues on mobile devices, particularly during transitions or translations.

Instead, consider using absolute or relative positioning for elements and dynamically adjusting the dimensions of surrounding elements using calc(). This approach works well on all devices without causing performance drawbacks. calc() enjoys strong support across browsers.

HTML

<div class="wrapper">
  <div class="content">
    <h1>Heading!</h1>
    <p>...</p>
    <h1>Another heading!</h1>
    <p>...</p>
    <h1>Yey! Another heading!</h1>
    <p>...</p>
  </div>
  <div class="banner">
    <img src="https://placehold.it/600x120" alt="ads" />
  </div>
</div>

CSS

body {
  margin: 0;
}

.wrapper {
  background: #981e32;
  width: 600px;
  height: calc(100vh - 120px); /* viewport height - fixed banner height */
  overflow-y: auto; /* ensures scrollbars appear when needed */
}

.banner {
  position: absolute;
  bottom: 0;
  max-height: 120px;
}

.content {
  padding: 1em;
  color: white;
}

.banner img {
  display: block; /* prevents inline elements from affecting height calculations */
}

Keep in mind that certain assumptions were made for illustrative purposes. Feel free to customize the code to suit your requirements.

SEE DEMO

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

Do not open iframe links in a new window

Is it possible to manipulate the iframe so that links open inside the iframe window? I want the links clicked within the iframe to stay within the same window instead of opening in a new one. However, I have too many links to individually edit their code ...

Toggle the jQuery class off when a different element is chosen

I've created a function that toggles a class to change the style of an element when it is selected. However, I'm facing an issue where the new style remains even when another element is selected. Is there a way to make the styling revert back to ...

Looking for a way to upload only part of a large file using HTML and PHP

Is it possible to create a PHP script that can upload only the first 1 MB of a very large file? Can this be achieved with a standard form upload in PHP by closing off the connection after 1 MB is uploaded? I have researched various uploaders (HTML5/Java ...

Allow only specified tags in the react-html-parser white list

Recently, I've been working on adding a comments feature to my projects and have come across an interesting challenge with mentioning users. When creating a link to the user's profile and parsing it using React HTML parser, I realized that there ...

Enhance React scrollbar functionality without relying on third-party dependencies

Currently working on enhancing the appearance of the scrollbar within my ReactJS project. Specifically, I am aiming for a design similar to this example: https://i.stack.imgur.com/2Q0P4.png Experimented with CSS properties like -webkit-scrollbar, -webki ...

The final element that fractures all its sibling elements positioned absolutely

I am experiencing an issue with a container div that contains 5 absolutely positioned images. When I specify the last image as absolutely positioned, all other images lose their positioning and stack at the top. The container itself is relatively position ...

What benefits does a dynamic website like this offer compared to one that is purely AJAX-based?

There are two main categories of dynamic websites that I define: The first type utilizes languages like PHP to concatenate an HTML page and send it back to clients. On the other hand, the second type uses an HTML template where all interfaces provide JSO ...

more concise jQuery script

Currently, I am a beginner in jquery and still in the learning phase. Although my existing code is functional and achieving the desired outcome, it feels lengthy and inefficient. I am seeking a way to streamline it and make it more dynamic. Specifically, t ...

Numerous Levels of Dropdown Menus

I am looking to implement a feature on a web page where users can select multiple vehicles using JQuery. The idea is that selecting the brand in the first dropdown will populate the second dropdown with the models available for that specific brand. The ...

How can AngularJS utilize ng-repeat and ng-bind-html to display arrays of HTML strings?

I'm currently attempting to display HTML strings from an array of HTML strings in my AngularJS project. As a newcomer to AngularJS, I have been trying to follow the examples provided on the official AngularJS website, but I am struggling to find a sui ...

Troubleshooting a navigation problem with DNN and Bootstrap-3 specifically for mobile devices

Here are the steps to demonstrate this issue: 1. Visit the following page of the website: 2. Resize your browser window to mobile size and close the menu using the icon. After the animation finishes, the navigation items reappear. I have been struggling ...

Can you customize the "rem" values for individual Web Components when using Angular 2's ViewEncapsulation.Native feature?

I'm interested in creating a component with ViewEncapsulation.Native that utilizes Bootstrap 4 while others are using Bootstrap 3. Below is the component code with Bootstrap 4: import { Component, ViewEncapsulation } from '@angular/core'; i ...

Displaying or concealing fields through Javascript depending on the category type of the results item

I am facing an issue with displaying certain fields in each individual property search result based on the property type. For example, if a property is classified as Land, I do not want the bedrooms and bathrooms fields to be visible, but if it is a Villa, ...

Issue with CSS Reset code causing disruption for one hyperlink

Check out the menu at this link: http://fiddle.jshell.net/V88c6/8/show/ To view the complete jsfiddle, click here: http://jsfiddle.net/V88c6/8/ Here is the HTML code: <div id="head_1"> <div class="inner"> <div class="column ...

I am attempting to create a form in NodeJs to search for a user in MongoDB by their telephone number using query routing. However, I am puzzled as to why this is not functioning properly

Can you identify the issue in this code? I am able to retrieve the correct mobile number on the console, but it is not being passed to the query routing on /search_user?mob. <input type="tel" name="message" id="mobile_input&qu ...

Modifying the color of drawings on a Javascript canvas

I am currently working on developing a drawing board using HTML and JavaScript (Node.js on the server side). One challenge I'm facing is implementing a color picker that allows users to change the paint color dynamically. While I could hard code the c ...

How to Implement Snap-Enabled Dragging in a Container Using jQuery UI

Issue Description (Fiddle): I am using the jQuery UI's .draggable() function to make the red element snap inside the blue container. However, it is snapping to one edge only instead of completely fitting inside (both edges). It requires further dragg ...

Trouble exporting to Excel on Chrome and Firefox browsers

I am having an issue with exporting tables to Excel using JS. The <table> tag contains some descriptions and a class (<table class="someClassName" border="0" cellpadding="0" cellspacing="0">). When the table is exported to Excel, the Excel fil ...

Is there a way to adjust the SVG level so that it aligns with the center of the polygon instead

Looking to align a simple svg icon for a dropdown button with the text in the button so that the centers match up. Currently, the icon is aligned with the bottom of the text instead. Here's the code for the svg: <svg xmlns='http://www.w3.org ...

Searching for data in a bootstrap table that is not case-sensitive

Searching for and highlighting text within a bootstrap table has proven to be a challenge. Check out the Fiddle for an example: https://jsfiddle.net/99x50s2s/74/ HTML <table class='table table-bordered'> <thead> <tr& ...