The concepts of justify-content and flex-grow are not being recognized or applied

My current issue involves CSS flexbox. Yesterday, my code was working perfectly fine, but today it suddenly stopped functioning as expected when I tested it. The problem seems to be related to flexbox.

Here is the desired outcome that I am trying to achieve:

  1. The ability to position the content using justify-content. Unfortunately, this feature is failing.
  2. The content should expand to fill all available space with flex-grow: 1. However, this is also not working correctly.
  3. The footer needs to be positioned at the bottom, as the content should push it down by taking up all available space through flex-grow: 1. This requirement is not being met.

It appears that the entire flexbox functionality is no longer working properly for me.

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

I suspect that the issue lies in the fact that flexbox is not responding correctly to even a simple declaration like:

justify-content: flex-start;

No changes occur when attempting other values such as center, flex-end, etc.

Interestingly, flexbox was cooperating as expected yesterday, allowing me to position elements using justify-content, yet today it refuses to work seamlessly.

Can anyone provide insights into what might be causing this misbehavior? Why are properties like justify-content: flex-end or justify-content: center not aligning the content correctly?

If I can resolve the issue with justify-content, I believe that flex-grow will function properly as well.

Is there any explanation as to why things are not behaving as intended?

I have managed to make flex work correctly using this online playground, confirming that my code should indeed be functional. The code snippet above mirrors exactly what I have implemented in the playground:

.ikigai {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.header, .footer {
  height: 80px;
  margin: 10px;
  border: 1px dashed lightgray;
}

.content {
  margin: 10px;
  border: 1px dashed lightgray;
  flex-grow: 1;
}
<div class="ikigai">
  <div class="header">this is a header</div>
  <div class="content">content</div>
  <div class="footer">footer 12</div>
</div>

https://jsfiddle.net/re01pn2x/

Answer №1

It seems like your flex container is missing a height specification.

As a result, it defaults to height: auto (adjusting based on content).

To address this issue, you can add the following code:

.ikigai {
   height: 100vh;
}

.ikigai {
  display: flex;
  flex-direction: column;
  /* justify-content: flex-start; */ /* default value; not necessary */
  height: 100vh;
}

.header, .footer {
  height: 80px;
  flex-shrink: 0; /* optional; if you don't want items to shrink vertically */
  margin: 10px;
  border: 1px dashed lightgray;
}

.content {
  margin: 10px;
  border: 1px dashed lightgray;
  flex-grow: 1;
}

body {
  margin: 0; /* override default margins; prevents vertical scrollbar */
}
<div class="ikigai">
  <div class="header">this is a header</div>
  <div class="content">content</div>
  <div class="footer">footer 12</div>
</div>

For more information, check out: How to make div 100% height of the browser window?


justify-content

Please note that the justify-content property may not have been functioning as expected due to lack of available free space in the container. This property distributes free space within the container, which was limited by the default height: auto.

justify-content & flex-grow

Additionally, using both justify-content and flex-grow simultaneously might lead to conflicts. Since flex-grow consumes any additional space created by a defined height, there might not be enough room for justify-content to allocate space effectively.

Answer №2

To solve this issue, you can use a height of 100vh;

.ikigai {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  height: 100vh;
}

.header, .footer {
  height: 80px;
  margin: 10px;
  border: 1px dashed lightgray;
}

.content {
  margin: 10px;
  border: 1px dashed lightgray;
  flex-grow: 1;
}

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

Managing the state of a flag: communicating between Angular2 header and sidebar components

In my Angular2 project, I was working on a layout folder where I divided common layouts of certain pages into three components: header, sidebar, and footer. There was an anchor tag in the header that, when clicked, needed to extend the header to the left e ...

Four identical columns with no outer margin and evenly spaced inner margins

This is a variation of the discussion on removing right and left border space in table-cell display elements. Despite attempting to use divs with equal inner margins, I encountered unexpected spacing causing the last div to wrap. You can view my attempt ...

Placing a picture within a box that is 100% of the viewport height

After searching for a while, I still haven't found a solution to my problem. I am currently working on a Personal portfolio that has different sections with a height of 100vh each. However, I am facing difficulty in positioning the images within the s ...

User interface for creating a platform resembling Product Hunt or Reddit

I am currently developing a web application similar to Product Hunt. The back-end API is up and running smoothly, and I have successfully implemented AngularJS for the front-end. However, I lack experience in designing the look and feel of the site. Shou ...

Selenium allows the liberation of a webpage from suspension

I'm facing an issue with resolving the suspension of a website as shown in the image below. My goal is to access a ticket selling website every 0.1 seconds, but if it's busy, I want it to wait for 10 seconds before trying again. Visit http://bu ...

Creating a dynamic layout in a fresh window with jQuery: A step-by-step guide

My goal is to create a dynamic layout using jQuery. The concept involves allowing the user to choose a width and height, which will determine the number of images displayed in rows and columns. The desired outcome is for the user to select a grid size (e. ...

Center the span element within Bootstrap 5 button groups

I am experiencing an issue where the span elements in my button groups are not aligning properly. I am looking for a way to align these span elements within the button groups without using fixed widths. Creating a basic web modal with Bootstrap 5 <di ...

The impact of CSS positioning relative on the height of an element

I need help with positioning elements in my HTML layout. I have one element stacked below another and am using relative positioning to nudge the bottom element up slightly so that it overlaps the top element. The paperOverlay element is positioned at the ...

Columns are not properly aligning side by side within the .card class

I am facing an issue where my cards are not lining up inline next to each other in columns but are instead jumping under each other. I have tried setting the col-md-6 class to align two of them next to each other, but that did not work. I have also checked ...

Click events are not functioning properly after an AJAX request is made

$(document).ready(function () { var user = 1; $("a.like").on("click", function () { var article = $(this).attr('data-article'); $.ajax({ type: "POST", url: "WebService.asmx/Like", ...

A guide to sending props to a CSS class in Vue 3

I need to develop a custom toast component that includes a personalized message and class. While I have successfully passed the message as props, I am encountering difficulties in applying the bootstrap class. Component File: Toast.vue <script ...

If the integer holds a particular value, take one action; if not, take a different course of action

My goal is to categorize my users from 1 to 7 and display a specific message based on their rank. If the logged-in user has Rank 7, they should see a message saying "you are staff". However, I've encountered an issue where assigning Rank 7 to multiple ...

R: Extracting data from web pages: The content appears to be formatted in XML but is not recognized as such; employing HTML

Working on scraping data from multiple years which are represented by different webpages. I have successfully extracted the 2019 data as expected, but encountering an error while attempting to preprocess the 2016 data in a similar manner. url19 <- &apos ...

Getting the css property scaleX with JQuery is as simple as executing the

I am struggling to print out the properties of a specific div element using jQuery. My goal is to have the different css properties displayed in an information panel on the screen. Currently, I am facing difficulties trying to show scaleX. Here is my curr ...

Preserve appearance when saving .html document (React)

Below is a simplified version of my React component: export class SomePage extends Component { downloadAsHTML() { const element = document.createElement("a"); const file = new Blob([document.getElementById('second-child-div').outerHTM ...

Is it possible to specifically focus on Google Chrome?

Can anyone help me with positioning the update button on www.euroworker.no/order? The button works fine in Firefox and Internet Explorer, but it's not displaying correctly in Chrome or Safari. I've tried targeting Safari and Chrome specifically, ...

Creating an HTML table for email transmission with Talend - how to do it?

Currently, I have a table that originates from a CSV file and has been converted to HTML using JavaRow in Talend before being sent via email. The code snippet used for this conversion is as follows: componentcontext.MsgCode = "<br><br><styl ...

Unable to center div container with margin set to auto

I'm struggling to center my container on the website. My goal is to have it centered and take up about 80% of the page so I can incorporate an image slider and text inside. Using margin: 0 auto doesn't seem to be achieving what I want. The backgr ...

Challenge with Bootstrap Popover: Unable to Capture Button Click Event inside Popover

First of all, here's a link to the problem on jsfiddle: jsfiddle.net The issue I'm facing is with a popover that contains html content including a button with the class "click_me". I've set up jQuery to listen for a click on this button and ...

Tips for resizing a background image horizontally without changing its height

Having a background image that is taller than the page and setting it as the background for the wrapper has caused some issues. Resizing the window results in a large amount of white space under the background image due to the fixed height of the wrapper. ...