What is the best way to ensure that the child flex box matches the height of the parent flex box by 100%?

As a beginner, I'm venturing into creating an experimental site for myself. However, I am facing an issue where the .menu-container does not seem to stretch 100% the height of the .container.

You can view the code on jsfiddle: https://jsfiddle.net/y1h2ervw/2/

CSS:

.container{
    width: 100%;
    display: inline-flex;
    justify-content: center;
}

.menu-container{
    height: 100%;
    width: 80%;
    display: inline-flex;
    justify-content: center;
    margin: 0px;
    padding: 0px;
}

.Menu{
    width: 75%;
    display: inline-flex;
    justify-content: space-between;
    font-family: Montserrat;
    background-color: rgba(82, 121, 111, 0.5);
}

.site-title{
    padding-left: 15px;
    cursor: pointer;
}

.nav-items{
    padding: 0;
    margin-top: 5px;
    display: flex;
    font-size: 1.2rem;
}

.nav-items > *{
    padding: 0px;
    font-weight: 600;
    color: rgba(38, 70, 83, 1);
    margin: 15px;
}

.nav-items >*:hover{
    color: white;
    cursor: pointer;
}

@media (max-width: 685px){
    .container{
        display: inline-flex;
        height: fit-content;
        width: 30%;
        flex-direction: column;
        font-size: 0.8rem;
    }

    .Menu{
        border-radius: 2%;
        display: inline-flex;
        flex-direction: column;
    }

    .site-title{
        text-align: center;
        padding: 0;
    }

    .nav-items{
        text-align: center;
        margin: 5px 2px 5px 2px;
        display: inline-flex;
        flex-direction: column;
    }
}

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Portofolio</title>
    <link type="text/css" rel="stylesheet" href="style.css" >
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@200&display=swap" rel="stylesheet">
</head>
<body style="background-color: #ffe8d6;">
    <div class="container">
        <div class="menu-container">
            <div class="Menu">
                <div class="site-title"><h2>Portofolio</h2></div>
                <div class="nav-items">
                    <div>First Year</div>
                    <div>Second Year</div>
                    <div>Contact</div>
                    <div>More</div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

I attempted to set height: 100% for the child flex box (menu-container) hoping it would inherit the size of the parent flex box (container), but unfortunately, it did not work as expected.

Answer №1

Experiment with this CSS rule for the .container element: height set to 100vh;

Answer №2

To create a positioning context for absolute child elements, add the CSS property position: relative; to the parent element .wrapper. Next, give the .menu-container a style of position: absolute;, and utilize

top: 0; bottom: 0; left: 0; right: 0;
to make sure it fills the entire height and width of .wrapper.

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

Tips on determining if a string is a properly formatted HTML:

My question is about checking whether selected strings in a web form are valid HTML syntax. How can I achieve this on a button click? function chkhtml() { var code = $("<table><td>"); code.each(function () { if( ...

Placing an Image in Next.js

I've been trying to position my image all the way to the right of the page using CSS properties like position: absolute and right: 0. I've also attempted setting the parent element's position to relative and the image's position to abso ...

angular use ngFor directive to restrict the number of rows displayed in a table

In my angular 6 project, I am trying to limit the display to just five rows in a table using ngFor. My current code snippet is as follows: <tbody> <tr *ngFor="let item of routines; let i = index"> <td style="display: none"> ...

Tips for preserving HTML markup in a Google Sheets cell without disrupting the tags

I am currently experimenting with using Google Sheets to input the complete HTML of an email into a cell, where I have variables for text, image src, href src, and more. As of now, I am utilizing Google Script to substitute tags with the corresponding val ...

Error in Javascript: Required variable missing for Sendgrid operation

I am facing an issue while attempting to send an email using sendgrid. Whenever I execute the function, it gives me an error saying "Can't find variable: require". Despite my efforts to search for a solution online, I have not been able to resolve thi ...

Is it possible to turn off GPU rasterization for a particular SVG element in Google Chrome?

There is a peculiar issue with the SVG graphic displayed on my webpage. On some computers, the complex linearGradient filling a Rect does not display all the Stops correctly, while on other computers it appears fine. I discovered that if I disable "GPU ra ...

Binding iframes in Angular 6

Is there a way to display iframe code stored in a variable within a div? Here's the HTML code: <div class="top-image" [innerHTML]="yt"></div> And here's the TypeScript code: yt = '<iframe class="w-100" src="https://www.you ...

Javascript variable unable to retrieve value from textbox

Hey there! I am having some trouble reading a textbox that is populated from the server into a JavaScript variable. When I try to access it, I get a console error saying "can't read from NULL". However, the text box is definitely populated with the st ...

The login form is not being recognized by Chrome

I've been working on creating a login form for my website. Oddly enough, when I try to use it on Chrome, it doesn't prompt me to save my password. Yet, it functions properly on other browsers like Edge, Firefox, and Internet Explorer. Here' ...

Is there a glitch in the Bootstrap v4 Navbar?

Encountering an issue with the default navbar example from Bootstrap's official website. The navbar is supposed to be full-sized and collapse when the screen size decreases. However, after implementing the code into my project, it appears as always co ...

Guide to generating an HTML table with database information employing jquery and ajax

I am faced with the challenge of creating a table using information retrieved from a database. Despite being able to view all the data through console.log, I am struggling to convert that into a table format. My latest version now displays at least one op ...

Vue.js app does not have the capability to display JSON data as a table

I successfully fetched JSON data in my vue app from the endpoint '/v1/api/sse?raceId=1', but I'm struggling to convert this JSON into a table format. The JSON is displaying correctly, but I'm unsure how to structure it into a table. He ...

Progress Bar Modules

I am currently working on creating a customizable animated progress bar that can be utilized as follows: <bar [type]="'health'" [percentage]="'80'"></bar> It is functional up to the point where I need to adjust different p ...

How can I assign a true or false value to an input variable in HTML using AngularTS?

I copied the following HTML code: <tag-input fullWidth id="inputDir" formControlName="inputDir" [modelAsStrings]="true" [placeholder]="'choice feature'" ...

What is the most effective method for incorporating a floating section next to a Susy gallery?

Check out my latest progress on the codepen here The number of items displayed in the gallery is dynamic based on search results. However, I am looking to add a fixed area to the right side that remains visible as the user scrolls through the gallery. Ess ...

Enhancing the KeyValuePair by incorporating additional value or parameter

I currently have a List<KeyValue<string, int>> that I utilize in the View of one of my applications. While it functions as intended, I am interested in expanding it by potentially incorporating an additional parameter/value to the KeyValue pair ...

Is there a way to soften the repetitive elements in the background image?

Is there a method to blur the part of a background image that is repeated, such that if it is positioned in the center, the sides of the image appear blurry as well? ...

Tips for updating the hover background color of a table row with a unique class in bootstrap

Modified: Here is the table along with its corresponding CSS styling: .table-hover tbody tr:hover { background-color: #fff !important; } <html lang="en"> <head> <meta charset="utf-8" /> <meta name="v ...

Display multiple values in a select dropdown using Bootstrap 5 properties

I am stuck with the following code<hr> HTML <select id="select" placeholder="Choose Select" class="selectpicker" multiple></select> <div class="container"> <div id="all" clas ...

A loop that incorporates a jQuery JavaScript dropdown menu along with some calculations

My goal is to have multiple dropdown lists populated from a PHP while loop. Each select dropdown has a corresponding textbox that should update its value when a selection is made. However, the current script only works for a single dropdown outside of the ...