CSS Assistance - Ensuring top div remains fixed while allowing bottom div to occupy remaining page space - Troubleshooting bottom div background issue

Currently in the process of building a new website and below is the initial code draft. Encountering an issue with the bottom content div. When there is less content, the bottom div fills up the remaining browser space just fine. However, when more content is added to the bottom div (resulting in page scroll), the background of the content div does not continue as expected. Seeking assistance in resolving this problem.

<html>
<head>
<style type="text/css">
* {
padding: 0;
margin: 0;
}
#container {
position: relative;
height: 100%;
width: 100%;
background: yellow;
}
#header {
height: 150px;
background: grey;
}
#content {
position: absolute;
top: 150px;
bottom: 0;
left: 0;
right: 0;
background-color: brown;
}
</style>
</head>
<body>
<div id="container">
<div id="header"></div>
<div id="content">
<p>body content</p>
...
// More body content here
...
</div>
</div>
</body>
</html>

Answer №1

To improve the layout, it is recommended to remove absolute positioning and apply the following CSS to #content:

#content {
  min-height: calc(100% - 150px);
  background-color: brown;
}

* {
padding: 0;
margin: 0;
}
#container {
position: relative;
height: 100%;
width: 100%;
background: yellow;
}
#header {
height: 150px;
background: grey;
}
#content {
min-height: calc(100% - 150px);
background-color: brown;
}
<html>
<body>
<div id="container">
<div id="header"></div>
<div id="content">
<p>Add body content here.</p>
</div>
</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

Enhance your website with Jquery-powered page transitions that can easily be linked for a

I have a client who has a specific vision for their website. To demonstrate the concept, I've created a demo which can be viewed here: She requested page transitions similar to those in the demo for the main content. I used jQuery to implement this ...

Having difficulty adjusting the color of the navbar in Bootstrap 4

I recently designed two navigation bars using bootstrap, but encountered an issue when attempting to change the background color of the second navigation bar. Despite following a tutorial video closely, the color did not update as expected. The main css fi ...

Implementing beans within an HTML form action allows for seamless communication between the form and

I am seeking assistance as I am unable to locate any tutorials online for the issue I am facing. How do you go about using a <bean:write....> within a <html:form....> The code I have written is: <html:form action="/restricted/client/so ...

Trouble with select box initialization resolved

I'm having trouble retrieving the selected value from a dropdown menu as it always returns the first value. Initially, the dropdown is empty. When I press a button to open the modal and populate the dropdown with options, it seems that the issue aris ...

When clicking on the dropdown items of another button, the class of the child element in the Bootstrap button dropdown is being removed

Check out the JSFiddle for this code snippet. I'm attempting to implement Bootstrap's drop-down menu using list items instead of options. When a list item is selected, the data should be retrieved and displayed as an active selection within a bu ...

The effectiveness of border-radius is limited to only one side of the div

After experimenting with applying the border-radius property to a div, I encountered an issue where the border radius only worked on one side when the radius value was too large. How can I resolve this problem while maintaining the border-radius value on a ...

Using Jquery Chosen Plugin to Dynamically Populate One Chosen Selection Based on Another

Good evening to all, please excuse any errors in my English. I have successfully integrated a jQuery Chosen plugin with my 'estado' field (or province). My goal is to populate another jQuery Chosen plugin with the cities corresponding to that s ...

Prevent leaving the body empty while populating a page with Ajax requests

I'm currently facing a dilemma at work. Our team is utilizing Bootstrap, jQuery, and a REST API to populate our web pages. Here's the sequence of events during page loading: The server receives a request A template is served which loads all ne ...

Ways to update HTML content generated by Ajax

Having some difficulties modifying the HTML content generated by AJAX. This is the code snippet from the page: @model IEnumerable<WE_SRW_PeerNissen.Models.Reservations> @{ ViewBag.Title = "List"; Layout = "~/Views/Shared/_Layout.cshtml"; } ...

Is there a way to create interconnections in all the HTML code I produce, without needing to use

Here is the code I am currently using. Strangely, everything below MSN.com turns into a link. I have double-checked my CSS and suspect that the issue lies there. However, I wanted to first explore if there might be an underlying problem in the HTML side of ...

What is the best way to ensure that a React app is always displayed in full screen

I am facing an issue while developing an app with React and Material UI. I am trying to display the app in full-page mode, but unable to achieve it successfully. Currently, it appears like this: https://i.sstatic.net/Hg0CA.png Here is my code snippet from ...

Having issues with the functionality of Bootstrap 4 sticky-top feature

How can I make the sidebar stick to the top across different screen sizes? It works fine for smaller screens up until the 'sm' breakpoint, but beyond that, it doesn't stick. I've tried adjusting the order of class names, but it didn&apo ...

Scrolling horizontally using jQuery and CSS

I have been experimenting with creating a horizontal scrolling page that moves to the right when scrolling down and to the left when scrolling up. Here is the current code: HTML <div class="scroll-sections"> <section id=&quo ...

What is the best way to target a class within a span using CSS?

I need help with hiding an icon from the mobile menu. I am unsure about how to target this specific class within the menu structure. <a class="funiter-menu-item-title" title="Nieuw">Nieuw<span class="icon fa fa-chevron-down"></span>< ...

What is the best way to place a child on top of a different parent in the stack?

There is a collection of figure tags, each with an expandable figcaption. Inside each figure, there is a clickable div that reveals the figcaption when clicked. However, the visible figcaption only overlaps the figure it belongs to and not others. Is there ...

CommentsController#new encountered a NoMethodError due to an undefined method called 'text' for the Comment with the following attributes: id: nil, author: nil, created_at: nil, updated_at: nil

I'm currently integrating rails with react to include a comments section in the app I am developing. While the /comments page is functional, I encountered an error when attempting to create a new comment. Despite consulting the guide I am following, t ...

Unable to modify the background color of the <SideNav> element

I've been working with react and recently discovered a side navbar design that caught my eye. However, I'm struggling to change the default background color from red. I've attempted creating custom CSS styles and adding className: bg-dark in ...

Guide on changing image source using a function

I am looking to dynamically set the img src="" attribute using a JavaScript function that changes the image based on a variable and checks its values: Here is the JavaScript code in the file: function myFunctionstatus(){ var ledactual = document.getE ...

Bootstrap button statuses confirmed

I am trying to implement a checked state for group checkboxes in Bootstrap 3.0.2. documentation This is the HTML code snippet: <div class="btn-group" data-toggle="buttons"> <label class="btn btn-default"> <input type="check ...

Error encountered in ASP.NET Core MVC due to dependency inversion with CRUD operations

Today I delved into dependency inversion. Prior to implementing this concept, my CRUD system was functioning well, but now I am encountering some errors. The error message says "Cannot implicitly convert type int to ContractLayer.UsersDto." In the image pr ...