Create a div element that expands to occupy the remaining space of the screen's height

I am trying to adjust the min-height of content2 to be equal to the screen height minus the height of other divs.

In the current HTML/CSS setup provided below, the resulting outcome exceeds the screen height. How can I achieve my desired effect? The footer (copyright section) is nested within content2, hence I need the height of content2 to match that of the screen exactly.


                body {
                    margin:0;
                    border:0;
                    background-color:#24373B;
                    color: #fff;
                }

                #headerBG {
                    min-width:980px;
                    background-color:#000;
                }

                #header {
                    width:980px;
                }

                #content1 {
                    width:980px;
                }

                #content2 {
                    width:960px;
                    padding:10px;
                    margin-top:30px;
                    background-color:#355258;
                    min-height:100hv; /* Issue may lie here */
                }
              
<body>
                  <div id="headerBG">
                      <div id="header">header</div>
                  </div>
                  
                  <div id="content1">content1</div>
                  <div id="content2">content2</div>
               </body>

Answer №1

Don't forget to use 100vh instead of 100hv as the minimum height. Here's the corrected code:

#content2{
    width:960px;
    padding:10px;
    margin-top:30px;
    background-color:#355258;
    min-height: calc(100vh - 50px);
}

Prior to using vw or vh units, make sure to define them in your CSS:

html {
    width: 100%;
    height: 100%;
}
body {
    width: 100%;
    height: 100%;
}

Answer №2

Using CSS table layout instead of viewport units like (vw, vh) can help achieve the desired effect. By setting up a table structure, you can make the height of the pink area expand to fill out all the available space automatically.

Check out this example on jsfiddle: http://jsfiddle.net/qtu89zhm/

html, body {
    height: 100%;
    margin: 0;
}
.table {
    display: table;
    width: 100%;
    height: 100%;
}
.row {
    display: table-row;
}
.cell {
    display: table-cell;
}
.box {
    width: 500px;
    margin: 0 auto;
}
.content-2 .cell, .content-2 .box {
    height: 100%;
}
.header .cell {
    background: gray;
}
.header .box {
    background: teal;
}
.content-1 .box {
    background: gold;
}
.content-2 .box {
    background: pink;
}
<div class="table">
    <div class="row header">
        <div class="cell">
            <div class="box">header</div>
        </div>
    </div>
    <div class="row content-1">
        <div class="cell">
            <div class="box">content1</div>
        </div>
    </div>
    <div class="row content-2">
        <div class="cell">
            <div class="box">content2</div>
        </div>
    </div>
</div>

Answer №3

If I've grasped your question correctly...

body{
margin:0;
border:0;
background-color:#555555;
  height:100vh;
  width:100vw;
}
#headerBG{
min-width:980px;
background-color:#AAAAAA;
  height:10%;
}
#header{
width:980px;
  height:100%;
  width:10%;
    
background-color:#FFF;
}
#content1{
width:980px;
  height:40%;
background-color:#000000;
  margin-left:5%;
  width:90%;
}
#content2{
margin-top:30px;
background-color:#FFFFFF;
  margin-left:5%;
  width:90%;
  height:50%;
}
<body>
<div id="headerBG">
    <div id="header">
    </div>
</div>
<div id="content1">
</div>
<div id="content2">
</div>
</body>

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

The use of a <button> element in a React App within a Web Component with Shadow DOM in Chrome disables the ability to highlight text

An unusual problem has arisen, but I have a concise example that demonstrates the issue: https://codesandbox.io/s/falling-architecture-hvrsd?file=/src/index.js https://i.stack.imgur.com/CkL4g.png https://i.stack.imgur.com/nDjuD.png By utilizing the divs ...

A guide on dynamically accessing an image from the src directory using props in a Vite + React application

export default function Card(props) { return ( <card> <img className={cardCss.card__img} src={`../assets/imgs/card/${props.img}`} alt="" /> <div className={cardCss.card__stats}> ...

Why Jquery's nth-child selection and conditional formatting are failing to work

I am working with a table and need to format specific data fields based on their content. For instance, any field less than 95% should be highlighted in red. Below is the jQuery code I am using: $(function(){ $('#ConditionalTable td:nth-child(2n ...

Determine the number of rows in an Ajax-fed datatable (including paginated rows) that have a specific value in a

I am struggling with counting rows in #datatableOne where the 'Status' column has a value of 'Unknown'. I have attempted a couple of solutions, but they are not giving me the desired results. The first solution only counts the rows on ...

What exactly is the functionality of the jQuery.on() method?

I am curious about the functionality of this function and how it operates. Does it follow these steps: Identify element(s) using their selectors Assign event-handlers to them Execute a setInterval on that selector, consistently delegating and then undeleg ...

Obtain the outcome of HTML5 FileReader by utilizing promises within an asynchronous function

I am encountering a challenge in my Angular 4 application where I am working with an image. I am trying to pass the base64 string to another variable, but due to the asynchronous nature of this process, the image.src ends up being empty. As a result, the ...

Customizing Material-UI: A guide to overriding inner components

Looking to customize the styles of a Material UI Switch for the small variation? I have applied global styles but now want to override the styles of elements like track and thumb. Targeting the root element with the sizeSmall class is working, but unsure o ...

I am having trouble getting bootstrap-icons to work in my Angular project and I'm eager to figure it out

I am having trouble incorporating bootstrap-icons into my angular project. Despite running the npm i bootstrap-icons command, I am unable to successfully add icons using icon fonts on my webpage. As a temporary solution, I have added the bootstrap icon CD ...

Is the Okta SDK compatible with all identity providers?

I am looking to incorporate a wide range of Identity providers into my app, such as Auth0 SSO OIDC, Onelogin SSO OIDC, Google SSO OIDC, and others. Is it possible to use this solution to make that happen? https://github.com/okta/okta-auth-js ...

The execution of consecutive Ajax requests encounters issues in the Google Chrome and Safari browsers

I am facing an issue where I encounter a problem displaying a sequence of dialogue or AJAX results that depend on each other. For instance, when a user clicks to send a message, it triggers an ajax call, which opens a dialogue box. The user fills out the f ...

Are there ways to incorporate extra icons into NavMenu in Blazor 8?

I am exploring ways to incorporate extra icons into the NavMenu.razor component of my Blazor version 8 application. In the earlier version, Blazor 7, there was an iconset setup located in wwwroot/css/, which allowed me to include additional icons simply by ...

How can I ensure that the HTML I retrieve with $http in Angular is displayed as actual HTML and not just plain text?

I've been struggling with this issue for quite some time. Essentially, I am using a $http.post method in Angular to send an email address and message to post.php. The post.php script then outputs text based on the result of the mail() function. Howev ...

Switchable radio options

Currently, I am creating a form containing multiple options that are mutually exclusive. However, none of these options are mandatory. That is why I want to enable the user to uncheck a selected radio button by simply clicking on it again. This way, all th ...

Enumerate the variable values that are validated using jQuery

I've made good progress with this in jsFiddle, but I can't seem to figure out why the first value isn't displaying a bullet point.. Check out my code on jsFiddle! <div id="checkboxes"> <input id="chkbx_0" type="checkbox" name= ...

Incorporating AJAX and jQuery to dynamically update a numerical value

I need to update the content within a span class using jQuery. The first line of my jQuery code is functioning correctly as it adds a new notification to the list. However, the second line that should replace the existing number with @unseen_notifications. ...

In PHP forms, ensure that only completed textboxes are submitted and empty textboxes are discarded

I've created a form that displays all available products from a database along with their prices. Users can input the quantity they want to purchase for each product, and upon submission, the total amount will be calculated. There are 5 products in th ...

Building a contact form in Angular and sending emails with Nodemailer

Currently, I am in the process of setting up a contact form for my website. Since I am utilizing a MEAN stack, it made sense to incorporate the nodemailer module for sending emails. In order to handle this functionality, I have established an endpoint &ap ...

The dictionary of parameters has an empty entry for the 'wantedids' parameter, which is of a non-nullable type 'System.Int32', in the 'System.Web.Mvc.JsonResult' method

The console is showing me an error stating that the parameters dictionary contains a null entry for parameter wantedids. I am trying to pass checked boxes to my controller using an array, so only the admin can check all boxes of tips for a specific user. T ...

Error: JSON at position 1 is throwing off the syntax in EXPRESS due to an unexpected token "

I'm currently utilizing a REST web service within Express and I am looking to retrieve an object that includes the specified hours. var express = require('express'); var router = express.Router(); /* GET home page. ...

I am having trouble with Node.js not properly handling POST requests and instead throwing a 505 error

I am a newcomer to nodejs and facing a roadblock in completing my project. I have been stuck for almost 2 days trying to resolve an issue with POST requests not being listened to by nodejs. Despite console logging, I keep getting a 405 error page. Here&ap ...