"Customize your footer with dynamic content at the bottom of the

I am seeking a logical review of a partial solution that I am not satisfied with. There is a table on my page created using DataTables, so the dynamic content means that the height and width of the table can vary. The table is wrapped in three div elements (which are necessary), and I need to control the height of the outermost div so that the footer remains at the bottom of the page.

Check out my JSFiddle for reference: http://jsfiddle.net/5hh9H/158/

This setup works well, except when both the content height of the table and the footer height are less than the window height.

The specific code I am addressing is:

if ($(window).height() < $("#wrapper").height()) {
    $("#table-container").height($("#wrapper").height());
} else {
    if ($(window).height() > $("#wrapper").height() + $("#footer").height() + 45) {
        $("#table-container").height($(window).height() - $("#footer").height() - 45);
    } else {
        // Unsure if this section is necessary vv
        $("#table-container").height($("#wrapper").height());
    }
}

In this scenario, the footer appears too low and cannot be seen when scrolled to the top. Any adjustments I make to the current function do not provide the desired smooth transition from the footer moving along with the bottom to stopping below the table (try clicking "Shrink Content!", scrolling to the bottom, and resizing the window). My goal is for the footer to remain visible at the bottom when the content is minimized and the page is scrolled to the top!

BEFORE https://i.sstatic.net/MxI8p.jpg

AFTER https://i.sstatic.net/JS3zn.jpg

Answer №1

To view the solutions, please visit this thread. Numerous methods can be utilized to achieve this task. However, it is worth noting that the accepted solution requires a footer with a fixed height. On the other hand, the alternative solution I presented eliminates this constraint (although I must admit that it may not be flawless).


If you prefer a CSS-based approach that is not reliant on fixed heights, consider using display: table.

CSS

html, body {
    height: 100%;
}
body {
    display: table;
    width: 100%;
}
.content {
    display: table-row;
    height: 100%;
}
.smallFooter {
    display: table-row;
    height: 1px;
}

HTML

<div class="content">
    <p>Insert main content here.</p>
</div>
<footer class="smallFooter">
    <p>Add footer content here</p>
</footer>

Check out the live demonstration on this fiddle

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

Retrieve the variable within the $.ajax function using the onSubmit event

After spending hours today trying to solve my problem, I found myself stuck. My form has a tag onsubmit="return checking();". The checking() function is responsible for input validation. function checking(){ var filename = $("#filename").val(); $. ...

What is preventing me from displaying the results on the webpage?

Currently, I am utilizing Express alongside SQLite and SQLite3 modules. However, upon running the server, the data fails to display on the initial request. It is only after a page refresh that the data finally appears. I attempted a potential solution by ...

Why does Drupal's Advagg display several css and js files?

After installing the Advag module, I noticed that it is combining files, but there seems to be an issue: <link type="text/css" rel="stylesheet" href="/sites/default/files/advagg_css/css__sqX0oV0PzZnon4-v--YUWKBX0MY_EglamExp-1FI654__IOPiOtulrIZqqAM0BdQC ...

Receive various results from buttons specified within a fancy box

I have a unique situation with a fancy box written in JSP that contains 3 buttons. I need to figure out how to return different values when each button is clicked - for example, button 1 returns 1, button 2 returns 2, and button 3 returns 3. As someone ne ...

basic computation of whole and decimal values using jquery

I'm having trouble multiplying 2 values in my code where the quantity is an integer and credit price is a decimal number. However, when I run the script, nothing seems to happen. Can someone please help me identify and resolve this issue? Any insight ...

Inquiring about the best method to determine the intersection point between two lines in Draw i.o

Can someone please explain how to find the coordinate point where two lines intersect in draw i.o? I am looking for a Javascript function to solve this issue and get the coordinate of the point only. For example: ...

Is there a way to prevent Express.js from triggering a file download in the browser?

I am attempting to preview a Word document file in the browser using an iframe: <iframe style="float:right;" src="/ViewerJS/#../demo/ohm2013.odp" width='400' height='300' allowfullscreen webkitallowfullscreen></iframe> (Fo ...

Ways to transfer data from TypeScript to CSS within Angular 6

Trying to work with ngClass or ngStyle, but I'm struggling with passing the value. Here's my current code: strip.component.ts import { ... } from '@angular/core'; @Component({ selector: 'app-strip', templateUrl: &apo ...

What is the best way to adjust the transparency of the document.body?

Is it possible to set the body of a website to have a low opacity while keeping a popup at full opacity to make it stand out? I attempted to specify the popup with opacity: 1 !important; but it didn't work as expected. Can you help me figure out how ...

Enhancing Web Security with AJAX and HTTP Access Control-Allow-Headers

I am currently developing a JavaScript library and I want users to be able to make requests to my server. To facilitate this, I have included the access-control-allow-origin and method headers in my server responses. Everything seems to be working well, b ...

What is the reason that when creating a fresh object within a for loop using the 'key' from the loop, it ends up being called key?

After delving into the world of JavaScript for about six months now, I've come across something that has left me puzzled. This is completely new to me, so I'm not entirely sure what's happening here. I am attempting to create a new object wi ...

Problem with using ng model GetText() method in Selenium WebDriver with Java

Action: Retrieving the value from a text box using the GetText() method with Selenium webdriver. HTML code: <input class="form-control ng-pristine ng-valid dirty ng-touched" type="text" placeholder="Search Query" my-enter="SaveBind('Search') ...

What are some techniques for utilizing CSS with form.ImageField in Django?

When attempting to apply CSS to form.ImageField in Django similar to CharField, I encountered an error. File "/Users/hogehoge/Desktop/hoge/hoge/forms.py", line 42, in PostForm photo = forms.ImageField(label='Image', validators=[fi ...

Incorporating jQuery Masonry for seamless overlapping effect while implementing infinite scroll

I've developed a script that enables infinite scrolling on my website: $(document).ready(function() { function getLastId() { var lastID = $(".element:last").attr("id"); $.post("2HB.php?action=get&id=" + lastID, ...

Swapping a Cube Mesh for a Car Mesh in ThreeJS

After developing a 3D cube that moves on one axis simulating the accelerometer sensor, I encountered errors when attempting to replace it with a car mesh. The errors are persistent and related to object definitions: https://i.sstatic.net/iTbGI.png Even t ...

What is the best way to eliminate products that have already been utilized?

Take a look at my code snippet. $(function() { $("#tags input").on({ focusout: function() { var txt = this.value.replace(/[^a-z0-9\+\-\.\#]/ig, ''); // only allow certain characters if (txt) $("<span/& ...

Alignment issue: Center alignment failing to work correctly

I'm currently working on a navigation bar with a central title and links to other pages aligned to the right. Despite using text-align: center, the title remains off-center. I've implemented a flexbox to ensure that the title and links are on the ...

A series of multiple jQuery document.ready() events in a SPA

Seeking advice on the best approach for handling multiple $(document).ready() calls in a single page app with a templating engine. Specifically, if the main page already has its own $(document).ready(), what is the recommended method for dealing with add ...

The scale configuration for scale: x is not valid for creating a time scale chart using chart.js

I am currently utilizing VueJS and attempting to integrate a time scale chart using Chart.js. However, I encountered the following error: Invalid scale configuration for scale: x Below is my configuration : First, I have a component named Chart.vue with ...

Is there a way to customize the color of an element within CardHeader in MUI?

Is there a way to customize the colors of {note.title} and {note.category}? I have attempted to do so by creating a theme: const theme = createTheme ({ palette: { category: { color: blue } } }) Unfortunately, this appro ...