The bottom section of the webpage fails to follow the CSS height or min-height properties

Taking into account the question I raised earlier:

How can a div be made to occupy the remaining vertical space using CSS?

I received an answer which I have been experimenting with lately:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Test</title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <style type="text/css" media="screen">

            html, body{
                padding: 0;
                margin: 0 auto;
                height: 100%;
            }

            #header {
                float: top;
                width: 100%;
                height: 15%;
                background-color: green;
            }

            #navbar {
                float: left;
                width: 20%;
                height: 70%;
                background-color: red;
            }

            #content {
                float: right;
                width: 80%;
                height: 70%;
                background-color: blue;
            }
            #footer {
                float: bottom;
                width: 100%;
                height: 15%;
                background-color: yellow;
            }

        </style>
    </head>
    <body>
        <div id="header"> Header </div>
        <div id="navbar"> Nav Bar </div>
        <div id="content"> Body </div>
        <div id="footer"> Footer</div>
    </body>
</html>

Ultimately, my goal is to achieve this:

To cover 100% of the screen while being able to choose how those percentages are distributed, for example:

html, body{
    padding: 0;
    margin: 0 auto;
    height: 100%;
}

#header {
    float: top;
    width: 100%;
    height: 15%;
    background-color: green;
}

#navbar {
    float: left;
    width: 20%;
    height: 70%;
    background-color: red;
}

#content {
    float: right;
    width: 80%;
    height: 70%;
    background-color: blue;
}
#footer {
    float: bottom;
    width: 100%;
    height: 15%;
    background-color: yellow;
}

In this setup, both html and body have a height of 100%, effectively filling the screen. The header takes up 15% in terms of height, the nav bar and body take up 70%, and the footer completes the remaining 15%, adding up to the full visible screen...

However, there seems to be an issue with my footer:

#footer {
    float: bottom;
    width: 100%;
    height: 10%;
    background-color: yellow;
}

Removing height: 15% allows me to see the yellow background color properly:

If I keep it, the color looks more greyish and occupies around 20% of the screen:

So, the main question now is how can I make sure that my divisions occupy the exact percentage height that I assigned to them?

I hope this all makes sense.

Thank you for your help.

Answer №1

It's important to remember that floating to the top or bottom is not possible in this context. Therefore, it is necessary to eliminate that concept from both your header and footer sections.

To clear the footer, simply add the following CSS:

footer {
  clear: both;
}

Answer №2

Your issue stems from the absence of:

float:top;

or

float:bottom;

The solution is to set both to float:left;

Below is your updated code for reference:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Test</title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <style type="text/css" media="screen">

            html, body{
                padding: 0;
                margin: 0 auto;
                height: 100%;
            }

            #header {
                float: left;
                width: 100%;
                height: 15%;
                background-color: green;
            }

            #navbar {
                float: left;
                width: 20%;
                height: 70%;
                background-color: red;
            }

            #content {
                float: right;
                width: 80%;
                height: 70%;
                background-color: blue;
            }
            #footer {
                float: left;
                width: 100%;
                height: 15%;
                background-color: yellow;
            }

        </style>
    </head>
    <body>
        <div id="header"> Header </div>
        <div id="navbar"> Nav Bar </div>
        <div id="content"> Body </div>
        <div id="footer"> Footer</div>
    </body>
</html>

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

Modify the parent div's style if there are more than two children present (CSS exclusive)

Is there a way to use the same class, like .outer, for both divs but with different styling for the parent element when there are more than two children? Kindly refer to the example provided below: .outer1{ border: solid 6px #f00; } .outer2{ b ...

Mastering the Art of Absolute Positioning in HTML Tables' Header Row

I have a table with 80 rows. How can I make the first row fixed? I attempted to add position: fixed; to the but unfortunately, it didn't work. Is there a way to achieve this using CSS or jQuery? <table> <thead> <tr> <td sty ...

Disabling an image is similar to deactivating a button

document.getElementById("buttonName").disabled = true; I have successfully disabled a button using the code above. However, I am now facing a challenge with using pictures as buttons that have an onClick function. Is there a way to disable the onClick fun ...

Attempting to retrieve the current time using JavaSscript

const currentTime = new Date(); const hours = now.getHours(); Console.log(hours); This block of code is returning an error message... Uncaught ReferenceError: now is not defined Please note that this snippet is written in JavaScript. I attempted to us ...

What is the best way to incorporate several php files into a WordPress post?

I have developed a system that retrieves information from a database and presents it in multiple text files. Now, I am looking to move this system to a page on a WordPress website. I have already created a custom page named page-slug.php and added the ne ...

An error occurred when attempting to run the command npm run compile:sass, displaying the message: npm ERR! missing script:

Everything seems to be in place with the sass folders and files, so what could be the issue? I have my package.json file set up correctly with the following code: { "name": "starter", "version": "1.0.0", " ...

What are the best methods for placing content within a box and ensuring it is responsive?

Having trouble solving a simple problem that seems to have an easy solution. The code I'm working on is meant to display multiple bubbles with similar content, but the text gets distorted due to using strange margin values to fit a specific resolution ...

Troubleshooting issues when utilizing flexbox in Firefox and Chrome version 48

Chrome 47 Behavior: The .scroll div scrolls correctly in Chrome 47, taking up 100% height using flex. Firefox Behavior: In Firefox, the .scroll div does not scroll properly and instead uses the content height. What is the solution that works across diffe ...

"Creating dynamic radio buttons within a dynamic table using Ajax and jQuery: a step-by-step guide for toggling

Looking to generate a dynamic html table with data retrieved from a web method in asp.net using Ajax jQuery. One of the fields is a boolean value that needs to be associated with radio buttons. However, encountering an issue where setting attributes like ...

How can I write the code to enable dragging the button for navigating to the next page?

<a draggable="true" class="user" id="leonardo" ondragstart="dragUser(this, event)" aria-selected="undefined"> IPD</a> If I want the button to navigate to the next page when dragged, what code should I write? ...

Adjusting the arrangement of elements based on the size of the screen

Two floating <div>'s are styled with classes .a and .b. Both <div>'s are floated to the left, each taking up 50% of the width, aligning them horizontally. On smaller screens, I want both <div>'s to be aligned vertically. ...

Ways to eliminate the unusual dashed space in ReactJS using Bootstrap

While developing an app with NextJS and Bootstrap, I noticed a strange dashed gap at the top of the screen in the elements tab. Despite checking for margin or padding-top properties on any element, there doesn't seem to be a clear cause for this issue ...

Request financial data from AlphaVantage using PHP

I'm currently working on utilizing the alphavantage API to retrieve currency exchange information. In order to obtain the desired data, I am using the following query URI: https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_cu ...

What is the method for specifying the HTML file extension within Visual Studio?

I am having issues with my project recognizing the CSS and other files in the HTML files I have created, even though I have double-checked the extension paths. How can I resolve this problem? https://i.stack.imgur.com/85ooE.png https://i.stack.imgur.com/F ...

Methods for enlarging a sub-element without any impact on its encompassing parent element

I need the child class to not affect the overflow of the parent when I hover over it. My initial thought was to remove the line position: relative; from the parent, but this solution does not work properly when dealing with multiple nested positions. .p ...

Using javascript to store HTML tags in a variable

Hey there, I have a quick question. Can someone help me figure out why this code isn't working? let plus = "+" + '<h1>'+"This is a heading"+'</h1>'; When I run the code, the output I get is: +<h1 ...

"Use jQuery to select all the cells in a row except for the

I found a visually appealing table layout that looks like this : https://i.stack.imgur.com/oRxYP.png What caught my attention is how clicking on a row selects the entire row. Take the example in the image above, where the second row is highlighted upon s ...

What is the significance of vendor prefixes in the world of CSS3?

While I can see the rationale behind using prefixes for experimental non-official features to avoid conflicts, what is the reason for using them on shadows and similar elements? Shouldn't all vendors be implementing effects consistently according to ...

What is the best way to eliminate duplicate values from a column in a data set

Time To Status Off-Track On-Track 10:28 AM gf 6233 4 4 10:32 AM dd 3835 7 10:40 AM ss 3235 4 10:43 AM ww 6621 5 11:06 AM zz 3837 ...

Ways to position a button at the bottom of a div and beneath an image

Hey there, I have a little issue that seems to be causing me trouble. My brain just can't seem to come up with the solution. Here's the HTML code: #div { position: fixed; top: 10%; left: 20%; right: 20%; bottom: 10%; ...