The height of a CSS child element is not automatically inherited from its parent with a specified height in viewport height units (V

Looking for help with a CSS issue here. I've tried searching online, but haven't found a solution that works for my specific problem.

I have a parent element (Bootstrap row) with a height of 100vh - 140px. The challenge I'm facing is getting the children of this parent to occupy a percentage of its height. I want one child to take up 100% of the parent's height, and the other two to take up 40% and 60%, respectively.

I've attempted using 'height: inherit;' as well as setting max-height to the desired percentage for compatibility reasons, but it hasn't worked as expected. I've tested in Chrome, Firefox, and Safari without success.

Here is the CSS code:

// Parent
#start-page {
    min-height: calc(100vh - 140px);
}
// Children
#init-square-1 {
    height: inherit;
    max-height: 100%;
}
#init-square-2 {
    height: inherit;
    max-height: 40%;
}
#init-square-3 {
    height: inherit;
    max-height: 60%;
}
HTML:
    <section id="start-page" class="row">
        <div id="init-square-1" class="col-xs-12 col-sm-6"></div>
        <div id="init-square-2" class="col-xs-12 col-sm-6"></div>
        <div id="init-square-3" class="col-xs-12 col-sm-6"></div>
    </section>

Answer №1

I figured it out! I just had to adjust the parent's height like this:

height: calc(100vh - 140px);

Instead of using:

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

Simply removing 'min' from the height property did the trick.

Appreciate the assistance!

Answer №2

The concept of using height: inherit; can be misleading as it doesn't directly inherit the height from the parent element, but rather from the parent configuration, which in this case is the div. Since a div element's default height is 0, it will inherit that value.

If you need to set the height to match that of #start-page, simply use height: 100%;

height: 100%;

Furthermore, consider adding a position: relative; to the outer container if necessary:

#start-page {
    min-height: calc(100vh - 140px);
    position:relative;
}

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

Avoiding the visibility of a concealed form in PHP

Can someone help me figure out how to hide a form on a page by default? I have a proxy with options, and I don't want the options to be visible until they are requested. I would like to have a link that reveals the options form when clicked. If you n ...

Tips for saving multipart/form-data using ajax in Laravel 5.6

Looking for help to submit a multipart/form-data form through ajax. I've tried various solutions found online, but none seem to work for me. Hopefully, someone can point out what I might be missing! This is the HTML code of my form. It's being r ...

Fluid pictures in Mozilla Firefox not fluid

My images are shrinking in Chrome, as expected, but they don't adjust their size in Firefox and IE9. I'm using the CSS below: .pics img { max-width: 100%; height: auto; width: auto\9; /* ie8 */ border: 1px solid #CCC; }​ ...

After making an Ajax call using AngularJS in a PHP file, I expected to receive only a success or fail message. Instead, I received the entire HTML page code along

After making an Ajax call using AngularJS in a PHP file, I expected to receive only a success/fail message. However, I ended up receiving the full HTML page code along with tags. Here is my AngularJS code: $http.post('ajax_Location.php',{ &apos ...

Enjoy watching a video by simply hovering over the highlighted words

I am looking to implement a function where the video plays when hovering over highlighted words and pauses when the mouse moves away. However, I am currently only able to get the video to autoplay upon hover, not the highlighted words. Any assistance on th ...

What is the process for enabling audio to start downloading immediately after the user clicks a button on the same webpage?

Can you please set up a function so that when users click on the "Download" button, the audio file automatically downloads? Product Details This beat is a melodic, bouncy, and hard track inspired by Lil Mosey. It is priced between $15-$75, with a master ...

Utilizing the combination of attribute binding and string interpolation

Looking to create an accordion similar to the one showcased on the Bootstrap website, but with the twist of dynamically loading data using Angular 2's *ngFor directive. I attempted setting the value of aria-controls dynamically like so: [attr.aria-co ...

Tips for Utilizing Environmental Variables within a Vue Application's index.html File

My website has an index file with all the necessary meta tags, stylesheets, and scripts: <!DOCTYPE html> <html lang="en"> <head> <!-- Required Meta --> <meta charset="UTF-8"> <meta http-equi ...

Distinguishing Between .files[0] and .value in HTML File Tags

While developing an AJAX file uploader, I encountered a challenge: I have to add the file to a FormData, but different browsers interpret the files attribute of the file tag differently (as defined in html5). Some browsers support it while others only rec ...

Exploring the diversity of perspectives through Angular

Currently, I am in the process of integrating multiple views in Angular to address the footer issue on a website that I am constructing. I want to ensure that the information I have been studying and attempting to replicate is accurate. Here is what I have ...

Picking out text areas enclosed by div elements

It seems like I find myself coming back here quite frequently to ask for help, but once again I am stuck. I am trying to select a textarea and enable editing in another textarea, which works fine with textboxes but not with textareas. Every time I click on ...

Is there a way to display a different file, such as index.html, based on the screen width?

I'm facing an issue. I have completed a web page (with HTML, CSS, and JavaScript), but now I want to create a mobile version using different HTML files, another index.html file, and a separate CSS file. What changes do I need to make in the main page ...

Step-by-step guide on downloading an image in HTML with the click of a button

I have a photo gallery on my website created using PHP and HTML. I am looking to add a functionality where users can click on a button to download the image that is currently set as a background of a specific div element in the gallery. The download button ...

Guide to customizing WordPress header menu buttons with CSS, excluding a specific button

I need help with custom CSS for my WordPress site. I want to apply a hover effect to all menu buttons except for the "Contact" button, which already has its own styling. The CSS code adds a growing line beneath the hovered menu item and a static line unde ...

The implementation of display flex is causing issues with the material-ui grid layout

Struggling to implement the grid system from material-ui due to an issue where grid items do not resize when resizing the browser window. The culprit seems to be a parent div with the style property "display": "flex". The dilemma arises from using a mater ...

JQuery is unable to validate a form that is being loaded from an external HTML file

I'm encountering an issue where my form imported into a separate HTML file is not validating using JQuery's $(form).validate() plugin. After following the guidance provided in this question, I successfully managed to get the form working. Howeve ...

Personalized element IDs and unique CSS styles

After editing the code snippet below... <div id="rt-utility"><div class="rt-block fp-roksprocket-grids-utility title5 jmoddiv"> I applied the changes in my custom.css file like this: #rt-utility .rt-block {CODE HERE} However, when attemptin ...

Tips for vertically aligning values in a Bootstrap table

Currently, I am working on generating reports for an NGO that conducts surveys in schools. Once the reports are created, they need to be sent out in a specific format. While a simple table structure would suffice, I have decided to use Bootstrap classes to ...

Tips for placing a button on the bottom of a window where the content expands

Seeking a solution to ensure the submit button is always positioned at the bottom of the page. While this can be done using position: absolute, bottom, there's a requirement to address. If the content height is less than the wrapping div height, the ...

Using AngularJS for Bootstrap alerts: A step-by-step guide

Hello there! I'm currently working on a project using Django and AngularJS. I'm trying to add Bootstrap alerts after the user submits some information. I want to show alert-success if the submission is successful, and so on. Can anyone help me wi ...