Utilizing CSS with flex to set the height to 100% of the

I've encountered an issue while constructing a page with the GWT framework where setting an element's height to 100% doesn't work.

Consider the following structure:

<div id="main">
        <div id="1">
            <div id="2"> 
                ...
            </div>
        </div>
    </div>

The main div cannot be altered since it belongs to the framework. Div 1 has the style display: flex;, and Div 2 has the style

display: flex; flex-direction: column; height: 100%;
.

When inspecting with Chrome Developer Tools, setting the heights of main div and div 1 to 100% results in proper content height, otherwise not.

My question is, how can I achieve this without modifying the main div, given that I don't have permission to do so?

Answer №1

It seems like you're interested in utilizing the flex: 1 property. From what I gather, you want the #main element to have a fixed height while its child <div> fills the remaining space. Here's a suggestion along with an example:

    <div id="main">
        <div id="one">
            <div id="two"> 
            </div>
        </div>
    </div>
    #one {
        display: flex;
        height: 100%;
        flex-direction: column;
    }
    
    #two { 
        flex: 1;
    }

Keep in mind that I changed the IDs for CSS selectors for clarity. Make sure to avoid starting IDs with numbers if you intend to target them using CSS selectors. Learn more about this here.

Check out the working example on JSFiddle.

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

Create a stylish layout with two div elements positioned side by side using flexbox for a responsive design

Struggling with my portfolio website, I encountered a challenge. I attempted to place two divs side by side, each containing text and an image. While the initial setup was simple, trying to make it responsive using flexbox has proven to be quite frustratin ...

js The correct value is not being set to the div's style.top

function gamestart(){ var gr; var gr = true; console.log(gr==true); if(gr == true){ console.log("we have activated pointer key detection dear Mr.ketsebaot") document.onkeydown = checkk; } } function checkk(e){ cons ...

What is the most efficient method for incorporating CSS styles? What are the advantages of using @

I am curious about the benefits and reasons for using @import to bring stylesheets into a pre-existing stylesheet, as opposed to simply including another... <<link rel="stylesheet" type="text/css" href="" /> in the head of the webpage? ...

HTML unable to render JSON data

My goal is to showcase a JSON outcome on my HTML page in the following format: { "error": false, "gal_providers": [ { "GalProvider": { "id": "132", "uid": "gp_522f1e047329f", "use ...

When clicking, the fixed header and footer suddenly shift out of place

In my jquery mobile application, I am facing an issue with a fixed header and footer. Whenever I click on the screen, the fixed header and footer get displaced and are no longer fixed. I am unsure how to resolve this bug. Any suggestions on how to fix it w ...

Can I set a nested DIV to a higher z-index than a parent DIV in IE7, so that it appears above it?

UPDATE!!! Apologies for the confusion, it turns out the issue was with the #container DIV missing "float:left;". Please check the HTML rendering in Firefox and IE7 to see the impact! I am facing difficulty getting a nested DIV to appear above another nes ...

When using AngularJS with DateRangePicker, I am encountering an issue where my ng-model does not capture the input text value when I select a date

Trying to establish the selected date range in an ng-model called dateRange in the following HTML. The input text field displays the selected value correctly, but dateRange remains null. What steps can I take to address this issue? <!DOCTYPE html> ...

What is the best way to implement lazy loading of images that have not been downloaded in a JavaFX WebView?

Currently, I am in the process of developing an email client application using JavaFX WebView to showcase email HTML files. In order to enhance its responsiveness and speed, my goal is to display inline images in emails as they are downloaded locally. Duri ...

Javascript-created HTML elements are failing to display on the webpage

As a newcomer to javascript, I am trying to dynamically create HTML elements using javascript for a class project. However, I am facing an issue where nothing is displaying on my page. Any help or guidance on what I might be missing would be greatly apprec ...

Animating width using CSS3 with percentage values

https://i.sstatic.net/SGEQZ.gif I've implemented CSS3 animations to expand the bars, but I'm facing an issue where the percentage needs to be embedded in the @keyframes-code. The custom width is currently inserted as inline CSS in the HTML. Is ...

Creating a dropdown button in HTML table cells with JavaScript: A comprehensive guide

I'm attempting to create a drop-down button for two specific columns in my HTML table, but all the rows are being converted into drop-down buttons. I only want the "categorycode" and "categoryname" columns to be drop-down. $(document).ready(functio ...

Skipping a JSON field in HTML/JavaScript when it is blank: A guide for developers

To develop an interactive program based on JSON input, I aim to display headers, subheaders, and choices derived from the JSON data. Some input fields may remain unfilled. For instance: Header Subheader Choice 1 Choice 2 Subheader2 Choice ...

jQuery can be utilized to iterate over a list and retrieve values, enabling the

I have this particular code snippet <div class="divShow"> <ul id="ulShow"> <li> <h3 class="CompanyShow">A</h3> <h2 class="ShowTitle">S</h2> <input class=" ...

Uploading Multiple Files in Google App Script

Seeking assistance from non-programmers! I came across a free sharing script for multiple uploads on the web: https://script.google.com/d/1x3p9ZAv-SafEK06r_Vr7fVuUNtEfBg1SGhmSYWjQ0kuPTk-y55a7Nink/edit?usp=sharing I'm not familiar with editing script ...

necessitated in specified input with assigned value

Here is some code I have: <!DOCTYPE html> <html> <body> <form action="/action_page.php"> <select required> <option value=1>Volvo</option> <option value=2>Saab</option> <option value=3>Merc ...

"Encountering an Internal Server Error while trying to submit the

Seeking Assistance: I am experiencing an error when attempting to send a contact form. https://i.sstatic.net/7sK58.jpg The Visual Basic code causing the issue: <% mail_to = "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail=" ...

The body element is inheriting the background-color

I am attempting to create a layout with two stacked elements and a footer. .background .container-fluid .footer You can view my code on this fiddle: http://jsfiddle.net/z9Unk/309/ My expectation is for the background to be displayed in green with the ...

Looking to incorporate a raw JavaScript file into a React project

I have successfully converted my HTML and CSS components to React, but I am facing some challenges with the JS part. I attempted to use react-helmet, but encountered an error: Cannot read property 'addEventListener' of null Here is my React.js f ...

Can a webpage be redirected to another page after an animation using only HTML and CSS?

My goal is to design a landing page that has a button allowing users to trigger an animation before being redirected to another page. This concept involves adding a captivating element before transitioning between pages, similar to a link with a dynamic ...

Issue with Bootstrap Alert functionality on local host page

My alert code isn't working as expected. I can't see anything on the screen, even though everything seems to be correct. I don't believe I'm missing any JavaScript functions since it's just a text alert. <div class="alert a ...