Ensuring DIVs are completely contained within their parent DIV using Fullscreen CSS and a height of

I found a nearly-perfect design using the code below:

https://i.sstatic.net/56i2E.png

This code provides the layout mentioned:

<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet"
        href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"/>
    <style>
        body {
            height: 100vh;
            min-height: 100%;
            border: 20px dashed gray;
        }
        .fullheight { min-height: 100%; }
        .left, .middle, .right { min-height: 100vh; }
        .left { border: 20px dashed red; }
        .middle { border: 20px dashed green; }
        .right { border: 20px dashed blue; }
    </style>
</head>
<body>
    <div class="container-fluid fullheight">
        <div class="row fullheight">
            <div class="left col-xs-4 col-md-4">
                <h2 class="text-center">Left</h2>
            </div>
            <div class="middle col-xs-4 col-md-4">
                <h2 class="text-center">Middle</h2>
            </div>
            <div class="right col-xs-4 col-md-4">
                <h2 class="text-center">Right</h2>
            </div>
        </div>
    </div>
</body>

This question is a continuation of this topic.

The potential solution can be seen in the response here. I tried to address the final issue where the left/middle/right boxes exceed their containing DIV.

A comment suggested:

calc(100vh - 40px)

What exactly does calc() signify within a CSS file? Also, how can I prevent the appearance of a vertical scroll bar? Its presence suggests that the content extends beyond 100vh.

Answer №1

It appears that the border is extending the height by 40px beyond its container. You can adjust this by ensuring the border displays within the divs by using the following CSS:

.left, .middle, .right { 
 min-height: 100vh; 
 box-sizing: border-box;
}

Alternatively, you can follow the suggestion in the comment and subtract 40px from the height using calc function like so:

min-height: calc(100vh - 40px);

Answer №2

https://developer.mozilla.org/en-US/docs/Web/CSS/calc

Utilize the calc() CSS function to execute calculations when defining CSS property values, allowing for a diverse range of units including length, frequency, angle, time, percentage, number, and integer.

With the use of calc, you can seamlessly incorporate mixed units, enabling precise value calculation at render time.

Additionally, it is crucial to remember:

Error occurs if division by zero is attempted during HTML parsing.

Ensure that the + and - operators are surrounded by whitespace, as omitting this whitespace may lead to incorrect interpretation of expressions.

The * and / operators do not require whitespace, although adding it consistently is recommended.

Mathematical expressions involving percentages in table layouts may be treated as if auto was specified.

Nesting calc() functions is permitted, with inner ones being treated like simple parentheses.

I have often found myself struggling with the sections highlighted in bold.

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

Tooltip not appearing when user hovers over it

I need help with displaying tooltips only when hovering over anchor tags. Initially, I have hidden the visibility and want to show it on hover. However, the tooltips are not appearing when I hover over them and there are no console errors displayed. Can so ...

Guide on connecting a URL with a generated ID to the <a href> element

I am currently working on building my own portfolio website using Django. The main idea behind this project is to create posts showcasing the websites that I have developed. These posts will be featured on a page titled "Projects," where viewers can click ...

Replacing the left styling using CSS

Struggling to adjust the position of a side panel that pops up when hovering over an option. This is the code I found in Chrome Developer Tools: <nav id= "side_nav" class= "sidebar-bg-color header-side-nav-scroll-show"> <ul ...

Use CSS properties to isolate and extract the logo from the Sprite image

If we have a sprite image, like the StackOverflow sprite, and CSS properties like: background-position: 0px 0px; width: 250px; height: 61px; We can use the Chunky PNG library to crop out a specific part of the sprite. However, some websites use negative ...

Transition smoothly with a fade-in effect as you scroll through the images, and proceed to

My Objectives: Implement a scrolling feature where images transition to the next one based on scroll movement. Create a cycle of images that automatically progress, with the view transitioning to the bottom section once all images are viewed. Currently f ...

"Enhancing security measures with multiple nonce for Content Security Policy

I am encountering an issue with my single page application, which is developed in .net core MVC 2.2. The application loads html sections on the fly. In the main document, I have added a Content Security Policy (CSP) policy with a dynamically generated hea ...

The button in the flex container is not wide enough due to center alignment

For my project, I implemented a CSS grid layout consisting of 20 rows and 20 columns (5% of screen for each cell). One particular page includes a button that initially fit within grid columns 5-8 and rows 6-9 without any issues. However, I wanted to center ...

I am looking to adjust the height of my MUI Grid component

Recently exploring React, and I'm looking to set a height limit for MUI Grid. I've structured my project into 3 sections using MUI grid components. My goal is to restrict the page height in order to eliminate the browser scrollbar. If the conten ...

Is it possible to add and delete DIVs simply by clicking on a link?

By utilizing a select dropdown list and appending the HTML code stored in the variable "code" (resembling <div>...</div>) right before the end of the div with ID mydiv using $(code).appendTo('#mydiv');. Within these dynamically added ...

Enhance Your List with Icon Decorations

Is it feasible to utilize a sprite image in place of the default bullet for an ul list? Is this achievable? ...

When updating the HTML content, JavaScript is outputting the code as text instead of running it

I am encountering an issue with adding the body content of a JSON file, which contains HTML code, to my existing HTML. Instead of executing the code, it appears as text within paragraph or header elements. I have searched through various discussions but ha ...

I am interested in displaying the PDF ajax response within a unique modal window

With the use of ajax, I am able to retrieve PDF base64 data as a response. In this particular scenario, instead of displaying the PDF in a new window, is it possible to display it within a modal popup? Any suggestions on how this can be achieved? $.ajax ...

Calculate the number of rows in a table that contain identical values

I have a puzzling issue that has been on my mind. I currently have an SQL statement that selects specific rows from my database and displays them in an HTML table, which is functioning properly. However, I now need to determine how many rows have the same ...

A step-by-step guide on enabling Autoclick for every button on a webpage

I am currently using Jquery and Ajax to carry out an action, my goal is for a code to automatically click on every button once the page has finished loading. Although I attempted to use the following javascript code to achieve this at the end of my page, ...

Tips for retrieving the selected option from a dropdown menu

I have a dropdown menu with checkboxes that can be selected using SumoSelect. Here is the markup for the dropdown menu: <select multiple="multiple" name="somename" id="uq" class="select"> <option value="volvo">Volvo</option> <o ...

Incorporate a smooth transition effect to a dynamically resizing div button

In my current setup, I have 3 buttons that can toggle between different visible divs. In the future, I may add more buttons to switch between additional divs. At the moment, the first div is active (display set to block), while all other divs are hidden ( ...

Display Text Only When Selected - Material-UI

Is there a way to display only the selected tab's text? I came across this code snippet in the MUI documentation that involves showing labels on selection. How can I achieve this effect, maybe by manipulating the state to change the color of the selec ...

Ways to include text underneath icons using HTML and CSS

Seeking guidance on how to display text below icons on my website. Can someone please provide instructions? <div class="bottom-bar div-only-mobile" style="position: fixed; bottom: 0; width:100%"> <a href="Dashboard"> <ion-icon name= ...

At what point do browsers automatically insert CSS styles as attributes without them being explicitly defined?

Greetings Code Gurus, I find myself grappling with an unexpected CSS anomaly while developing a website. Here is the puzzling code snippet: <div id="..." style="padding-bottom: 78px; padding-top: 78px;" >...</div> These styles are manifesti ...

Site optimized for mobile devices

I need to create a website that is optimized for mobile devices like Android, iPhone, and Blackberry, as well as desktop and tablet. The screen resolutions of these devices can vary greatly. My supervisor has suggested developing one site that can adjust ...