The uniform height of flex columns was spoiled by a child element with a display setting of flex

CSS:

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
body {
  display: flex;
  background-color: #F5F5F5;
}
body > header {
  display: flex;
  position: fixed;
  width: 100%;
  height: 60px;
  align-items: center;
  background-color: #373737;
  -webkit-box-shadow: 0 3px 3px rgba(0, 0, 0, 0.19);
  box-shadow: 0 3px 3px rgba(0, 0, 0, 0.19);
}
aside {
  width: 250px;
  background-color: #484848;
  font-size: 18px "SL";
  margin-top: 60px;
}
aside > ul.side-menu {
  list-style-type: none;
  margin-top: 25px;
  width: 100%;
}
aside > ul > li > a {
  display: block;
  text-decoration: none;
  font-family: "SL";
  font-size: 18px;
  line-height: 40px;
  padding-left: 20px;
  color: #CCCCCC;
  border-bottom: 1px solid #8E8E8E;
  transition: 300ms;
}
aside > ul > li > a.active {
  color: white;
}

HTML:

<body>

  <header>

  </header>

  <aside>
    <ul class="side-menu">
      <li><a href="#" class="active">123</a></li>
      <li><a href="#">123</a></li>
      <li><a href="#">123</a></li>
      <li><a href="#">123</a></li>
    </ul>
  </aside>
</body>

Codepan:

https://codepen.io/UADev/pen/zzmdPG

Upon expanding to fullscreen, the following behavior is observed:

https://i.sstatic.net/j6omE.png

An attempt was made to use height: 100% on both the body and html elements, however it did not work as expected when there was another flex element with flex-wrap: wrap inside one of the child elements like aside or section. Removing the display:flex property from one of those elements caused layout issues, yet resolved the problem.

Answer №1

To ensure that the children elements fill the height of its parent, simply apply min-height: 100vh to the parent element (body). This will make use of the default value align-items: stretch for the children.

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
body {
  display: flex;
  background-color: #F5F5F5;
  min-height: 100vh;
}
body > header {
  display: flex;
  position: fixed;
  width: 100%;
  height: 60px;
  align-items: center;
  background-color: #373737;
  -webkit-box-shadow: 0 3px 3px rgba(0, 0, 0, 0.19);
  box-shadow: 0 3px 3px rgba(0, 0, 0, 0.19);
}
aside {
  width: 250px;
  background-color: #484848;
  font-size: 18px "SL";
  margin-top: 60px;
}
aside > ul.side-menu {
  list-style-type: none;
  margin-top: 25px;
  width: 100%;
}
aside > ul > li > a {
  display: block;
  text-decoration: none;
  font-family: "SL";
  font-size: 18px;
  line-height: 40px;
  padding-left: 20px;
  color: #CCCCCC;
  border-bottom: 1px solid #8E8E8E;
  transition: 300ms;
}
aside > ul > li > a.active {
  color: white;
}
<body>

  <header>

  </header>

  <aside>
    <ul class="side-menu">
      <li><a href="#" class="active">123</a></li>
      <li><a href="#">123</a></li>
      <li><a href="#">123</a></li>
      <li><a href="#">123</a></li>
    </ul>
  </aside>
</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

Using createStyles in TypeScript to align content with justifyContent

Within my toolbar, I have two icons positioned on the left end. At the moment, I am applying this specific styling approach: const useStyles = makeStyles((theme: Theme) => createStyles({ root: { display: 'flex', }, appBar: ...

The parent div will not accommodate two nested divs

I'm having an issue with two divs inside a parent div not being contained within the container when I inspect the page, even though I've wrapped the div around the other 2 divs. My goal is to apply attributes to the parent div instead of each in ...

toggle visibility of <li> elements using ng-repeat and conditional rendering

I have an array of color IDs and codes that I'm utilizing with ng-repeat in the <li> tag to showcase all colors. However, I only want to display colors where the color code is less than 10, hiding any colors where the color code exceeds 10. Addi ...

Is it possible to use speech recognition on browsers besides Chrome?

Is there a way to utilize a microphone with JavaScript or HTML5 without relying on Flash technology? I was able to achieve this in Chrome by using webkit-speech, but I am looking for solutions that will work in other browsers as well. Any suggestions wou ...

Link an HTML contact form to an Express.js backend server

Hey there, I'm a newcomer to web development and I've been working on creating the backend code for a contact form, but it keeps throwing errors. Here's my HTML code for the contact form: </div> <div class="row"> ...

Highcharts - Troubleshooting the chart reflow feature

Take a look at the fiddle I created. I encountered an issue with the chart width when toggling the sidebar. After seeking help on Stack Overflow from this post, I was able to solve it. Now, I'm facing another bug where adding transitions while togg ...

Steps to resolve transition zoom issues with images

I'm having trouble showcasing blog posts with an image. Currently, I am utilizing card-columns from Bootstrap 4, and when the user hovers over the image, it scales up. The issue arises when the transition occurs, as my border radius resets to defaul ...

Unlock the power of VueJS with advanced checkbox toggling for array data

I have encountered an issue while working with VueJS regarding the implementation of two features for a set of checkboxes. Initially, the checkboxes are generated dynamically. I am in need of a master 'toggle' checkbox that can toggle the stat ...

The mysterious height phenomenon when setting the width of a list item with jQuery

Consider a basic ul and li setup similar to this: <div id="middle"> <ul> <li> <a> bridal </a> </li> //.... </ul> </div ...

Tips for adjusting the height of the NextJS Image tag based on the width of the screen

I'm leveraging next/image to display my image in the following way: <Image src={imageLink} width="1920" height="512" alt="Hero Image" /> Everything works well for screen widths larger than 750px. Is there ...

Best practices for selecting checkboxes and transferring values to another page in PHP/HTML

Apologies for my lack of experience in PHP. I am in the process of creating a project without any knowledge of PHP. I have set up a database with a list of users and can display users based on specific information through a search. Each search query has a ...

Implementing CSS styling within a JavaScript file

I have a vague memory of an easy way to incorporate CSS code within a JS file, but I can't recall the specific details. Simply inserting CSS code into a JS file doesn't seem to work, so there may be a need for comments or some other method. *No ...

Tips for positioning an element so that it remains anchored to the content it is placed within

Hey Everyone! I'm struggling a bit with how to position the h2 headings in my code so that they stay fixed in the top right corner of the box while moving along with the rest of the contenthttps://i.stack.imgur.com/OOVaA.png%60 What I'm attempt ...

Accessing pseudo elements when their sibling is hovered can be achieved by using CSS selectors and combinators

I am struggling with the following html code: <div class="content"> <h2><a href="#">Hero</a></h2> <h2>Hero</h2> <div class ="tricky"></div> </div> The "co ...

applying different styles to various elements

As a newcomer to the world of jQuery, I am attempting to achieve the following goal: I have several instances of a div, and for each instance, I randomly assign a class from a predefined list in order to modify certain attributes. While this process is su ...

I'm encountering an issue where the data in my personalDeatail model's add value is not updating automatically. Can someone please help me

I've been struggling to automatically update the data in model personalDetail.add value when adding two column data. The added data appears correctly in the input box, but it's not updating in personalDetail.add. What am I missing here? Help need ...

JavaScript resets the timer whenever the page is refreshed

Is there a way to maintain the timer in a quiz even after refreshing the page? <html><h1>Js Timer</h1> <div style="font-weight: bold;" id="quiz-time-left"></div> <script type="text/javascript"> var total_seconds = ...

Problem with displaying fonts in web browsers

I decided to create a React App using the Material UI library, but I wanted to customize it by changing the default font from Roboto to Overpass. I successfully imported the fonts using their library. <link rel="preconnect" href="https:// ...

Show only the image source (img src) and do not display the audio and video sources using jQuery

In my code, I need the following conditions to be met: when an image is posted from the backend, the video and audio sources should automatically hide; when a video is posted, the image and audio sources should hide; and when an audio file is posted, the v ...

Navigate to a fresh web page without encountering any script loading issues

I am currently working on a web application that loads new pages without requiring the browser to reload. While some pages load perfectly fine, others are causing errors due to missing scripts. The code snippet below is used to load a new page: function lo ...