Troubleshooting problem with HTML height responsiveness

Currently, I am in the process of creating a basic responsive HTML template that consists of three sections – header, body, and footer. The design includes images for both the header and footer, as well as a background image for the body section. However, I am facing an issue where the footer is not fixed at the bottom of the page, and I would like to limit the maximum height to 1024px.

Here is how the layout is supposed to look:

And here is the current output:

I have tried various combinations of CSS styles, but I cannot seem to figure out what is causing the problem with my code.

Below is the complete code snippet:

<!doctype html>
<html>
<head>
    <title>Put your title here</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style>
    html, body {
        margin: 0;
        padding: 0;
        width: 100%;
        max-height: 1024px; 
        background-image: url(landing-page3.jpg);
        background-repeat: no-repeat;
        background-size: 100% 100%;
    }
    .wrapper {
        height: 100%;
    }
    .main {
        height: 70%;
    }
    .header {
        height: 15%;
    }
    .footer {
        height: 15%;
    }
    </style>
</head>
<body>
    <div id="wrapper" class="wrapper">
        <div id="header">
            <img src="headerf.png" style="width:100%;">
        </div>
        <div id="main">
            Lorem Ipsum is simply dummy text of the printing and typesetting industry...
        </div>
        <div id="footer">
            <img src="footer.png" style="width:100%; position: absolute; bottom: 0;">
        </div>
    </div>
</body>
</html>

Answer №1

Issue: The footer in your HTML is assigned the id of #footer, but in your CSS it is defined as a class using a period like this: .footer

Your CSS code looks like this:

.footer {
   height: 15%;
}

While your HTML code appears as follows:

<div id="footer">

Solution :

.wrapper {
    height: 100%;
    border:1px solid red;
    position:relative /* added */
 }
 #footer {
    position:absolute; /* added */
    height: 15%;
    bottom:0; /* added - fix to bottom */
    left:0; /* added -for full width */
    right:0; /* added -for full width */
}

Additionally, in both your html and body elements, you have set max-height but not height, resulting in the parent element of the wrapper not inheriting 100% of the browser height.

 html, body {
        margin: 0;
        padding: 0;
        width: 100%;
        max-height: 1024px;
        height: 100%;/*missing*/
        background-image: url(landing-page3.jpg);
        background-repeat: no-repeat;
        background-size: 100% 100%;
    }

See demo here


UPDATE

Instead of placing an img within the footer, consider setting it as a background image instead.

     #footer {
         min-height: 15%; /* will adjust content if higher than 15% */
         width:100%;
         background-image: url(http://www.smarthosting.rs/footer.png);
         background-repeat: no-repeat;
         background-size: 100% 100%;
     }

Check out the updated demo here

Answer №2

If you're in need of a solution for a persistent footer, a sticky footer may be just what you're searching for. Learn more about implementing this design technique from Chris Coyer's Sticky Footer example, and customize it to fit your preferences. This resource could prove to be invaluable in achieving the desired outcome.

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

extract all hyperlinks from a specific div using JSoup

Hey there, I am currently utilizing Jsoup to parse through a website and my goal is to extract all the links from the provided HTML code: <ul class="detail-main-list"> <li> <a href="/manga/toki_wa/v01/c001/1.html" title="Toki wa... ...

How can I retrieve the source code of a popup window and save it as

Is there a method to save the content of a popup window from an external domain as a string, when opened with: window.open('html'); Alternatively, is it possible to redirect the output of the popup into a string? For example, using Chrome' ...

What are the steps to customize the CSS style of a specific button in my dialog box?

I am trying to set the style for my dialog button in my JSP. The code I'm using is affecting both buttons, but I want to apply individual styles to each one. Currently, I am using jQuery version UI 1.9 Here's a fiddle link jQuery code: $(&apo ...

The visibility of HTML elements is dependent on the presence of space

Utilizing the onkeyup event in Javascript, I am capturing the text entered into a contenteditable div and transferring it to an input field. Users have the ability to apply bold or italic styles to the selected text by highlighting and clicking on the res ...

What method is recommended for saving data in an HTML data attribute?

Is there a way to store multiple values in an HTML data-attribute and retrieve them using jQuery? When storing values, is it best to use comma-separated or space-separated values? If I need to find <li> tags with "Mango" in the data-fruit attribute ...

The styling for the mat datepicker is not appearing as expected

I am facing an issue with the mat datepicker as its style is not displaying correctly on the web page. I attempted to add the necessary styling to the styles.less file. @import "~@angular/material/prebuilt-themes/indigo-pink.css"; I also made s ...

Disable body scrolling on mobile devices in native browsers

When using the native browser on Samsung Galaxy S5 / S6, the following CSS code: body { overflow: hidden; } does not successfully prevent the body from scrolling. Is there a way to work around this issue? Edit: As mentioned below, one workaround is t ...

How can I use ngx-editor to insert an HTML block at the current cursor position by clicking a button?

I am currently using ngx-editor within Angular 7. My goal is to insert HTML at the cursor's position upon clicking on parameters from a list. The current view displays how the parameter is appended when clicked, as shown in the image attached https:// ...

How can I use jQuery to pre-select an option in two connected dropdown lists that are populated with JSON data?

I am currently dealing with two interconnected dropdown lists for country and city selection. The options are populated using JSON data, but I've encountered a couple of issues along the way. The first issue is: How can I set the default selected opti ...

What is the process for displaying the table on my website using the code?

I need help integrating a league table into my soccer blog. I found this site with the code to display the league table. How can I use this code to show the table on my website? Check out the source here Here's the code: <iframe frameborder="0" ...

Modifying the CSS display property in Javascript following a media query update

Seeking a solution for a table that needs to be visible on desktop but hidden on mobile, with the option of clicking a button to toggle its visibility. Currently, the javascript function close_table() sets display:none which overrides the CSS display:block ...

Steps for inserting an additional header in an Angular table

https://i.stack.imgur.com/6JI4p.png I am looking to insert an additional column above the existing ones with a colspan of 4, and it needs to remain fixed like a header column. Here is the code snippet: <div class="example-container mat-elevation-z8"> ...

Default values for CSS variables: only apply if the variable has not been previously defined

My Web Component relies on the power of CSS variables. To set default values for these variables is crucial. With their wide usage across multiple files, it's essential to define them once and for all. The initial approach turns the text color to b ...

Automatic table width expansion with CSS

I'm in the process of creating a new website, and I want the layout to resemble the following: +---+--------------+ |# | | |n | #page | |a | table.basic | |i | | |g | | |a | | |t | ...

Using CSS to align horizontally the legend of keys and values

I'm currently working on designing a horizontal legend using html/css. The design consists of colored boxes with text beside them, followed by some spacing, then another colored box with more text, and repeating in this pattern. [blue] - LabelA [g ...

What could be the reason for my desktop saved image not showing up on my HTML website?

After finding this code snippet online, I decided to incorporate it into my HTML website by displaying an image saved on my desktop. However, despite adding the image path (â€ĒC:\Users\chan tien fatt\Pictures\homework4.jpg) to the code, ...

PHP - Easily send emails with attachments

Below are the codes I am using to send an email with an attachment: if (isset($_POST['submit'])) { @$name=stripslashes($_POST['name']); @$last_name=stripslashes($_POST['last_name']); @$phone=stripslashes($_POST['phone&a ...

Tips on utilizing multiple dynamically generated toggle switches efficiently

As a Frontend beginner, I am working on implementing toggle switches using HTML, CSS, and Vanilla JavaScript. Approach: I am generating an HTML table with multiple rows based on the data from my Django database. Each row contains details like name, id, a ...

How can I use pinching gestures to zoom in and out on an image in the ASP.NET framework and HTML5?

I'm developing an iPad app and utilizing the ASP.NET framework along with HTML5 and Mobile jQuery. Any tips on how to accomplish this? Thank you! ...

using javascript to animate multiple div elements

In my current project, I am harnessing the power of Javascript to incorporate some eye-catching animation effects on a rectangle. Once the animation is complete, I have set the box to disappear from view. Check out the code snippet below for more details: ...