Ensure each individual flex item stretches to their specific needs

Is there a way to make child-6 stretch to half the height of its parent without splitting the 6 items into 2 groups? I've tried stretching child-6 but it doesn't seem to work as expected. It makes sense that stretching a specific item will consume the remaining space, not necessarily half of the container's height.

.parent {
    width: 600px;
    margin: 0 auto;
    padding: 10px;
    height: 300px;
    background-color: #eee;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    align-content: space-between;
}

.parent div {
    color: #eee;
    background-color: rgb(29, 28, 27);
    padding: 10px 0;
    width: calc(94%/3);
    display: flex;
    justify-content: center;
}
.parent div.ch6 {
    align-self: stretch;
}
<div class="parent">
     <div class="ch1">1</div>
     <div class="ch2">2</div>
     <div class="ch3">3</div>
     <div class="ch4">4</div>
     <div class="ch5">5</div>
     <div class="ch6">6</div>
</div>

Answer №1

Check out the code snippet below:

.container {
  width: 600px;
  margin: 0 auto;
  padding: 10px;
  height: 300px;
  background-color: #eee;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
}

.container div {
  color: #eee;
  background-color: rgb(29, 28, 27);
  padding: 10px 0;
  width: calc(94%/3);
  display: flex;
  justify-content: center;
}

.container div.item6 {
  align-self: stretch;
}
.container div.item5,
.container div.item4{
  align-self: end;
}
<div class="container">
  <div class="item1">1</div>
  <div class="item2">2</div>
  <div class="item3">3</div>
  <div class="item4">4</div>
  <div class="item5">5</div>
  <div class="item6">6</div>
</div>

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

What could be causing the sporadic functionality of my jQuery image resizing code?

Seeking help for an issue I am facing with my jQuery code. I have been trying to scale a group of images proportionally within an image carousel using jCarousel Lite plugin. However, the resizing code seems to work randomly and I can't figure out why. ...

A guide on dynamically sending data to a PHP script when an input is changed and displaying the results in a

I am trying to implement a feature where the data inputted into a text field is sent to posttothis.php and then the result is displayed in a content div. However, I am encountering difficulties in making it work. testscript.html <html> <head> ...

Adjust the height in proportion to the width

My goal is to adjust the height of the li's based on their width using JQuery. var width = $('li').width(); $('li').css('height', width + 'px'); However, I've encountered an issue as it doesn't resu ...

Can we access an element within the document using its context?

One common method to access an element is by using its id: <div id="myId"></div> <script type="text/javascript"> $(document).ready(function(){ $('#myId').something(); }); </script> However, there are inst ...

Unable to access .php file on new server using JQUERY AJAX .get

After migrating my website to a new server, I encountered an issue where all the $().get("whatever.php") calls were failing. Previously, everything was functioning properly but now none of the requests are even reaching the php script. For instance: inde ...

Avoiding HTML (JSX) tag duplication in React Component

Having the same code in my React component multiple times is becoming repetitive and inefficient. Is there a way to follow the DRY principle and avoid repeating this code? While creating a landing page with Sass styling, I noticed that I am duplicating t ...

How to trigger the submission of a form within the submission event of another form using jQuery

I am encountering an issue with having two forms on a single page. Whenever I click on the submit button of the parent form, the parent form's submit event is triggered. In this event, I have included logic to submit the second form using the submit m ...

Challenges with the Task List Board

I'm facing a bit of a challenge with this task. As a newcomer to JavaScript, I've set out on a quest to create a task list board where users can input tasks along with dates and times. The goal is for these entries to appear inside a photo using ...

Tips on ensuring iframe is consistently centered

I have a div element enclosing an iframe, and I am trying to always position it in the center. Here is my attempt on jsfiddle: jsfiddle I truly believe that someone could help because I am certain that it is something simple but I just can't figure i ...

Creating a clickable pagination box involves utilizing CSS to style the entire <li> element with the necessary properties

Is there a way to make the entire LI box clickable for the pagination box? The HTML and CSS parts are functioning correctly, as I am able to click the link with the page number to navigate to the next page. However, the issue arises when trying to click t ...

Is it possible to retrieve specific information from a website using the rvest package?

I've been attempting to extract and display the review rating of a song through web scraping using rvest in R from Pitchfork. The rating for this particular song is 8.5, but unfortunately, I am encountering an issue as shown below: https://i.sstatic.n ...

Using JavaScript to Show Variables When Clicked

I have been working on populating multiple divs with data stored in variables that change when an image is clicked. Here's a snippet of the code within my tag:</p> <pre><code>function displayName(name){ document.getElementById( ...

Setting the font-size in HTML/CSS to dynamically adjust and fill the entire width and height of its

I'm trying to make a <div> element adjust its size based on the browser window. Within this <div>, there is a paragraph of text: <div style="width:80%; height:80%; margin:10%;"> <p>Paragraph of text. Paragraph of text. Pa ...

Is there a way to remove this annoying line? Or perhaps just reformat it somehow?

I seem to be overlooking a small detail. I have created an html table with Bootstrap5 css, but I am struggling with the formatting. How can I remove the black line or adjust the boldness of the text in the table header? Check out the Table Header Row Bel ...

Attempting to include a standard VAT rate of 5% on the invoice

/* The code format is correct and I don't see any issues on my end, I hope it works well for you. */ I need assistance in adding a fixed VAT (tax) rate of 5%. The tax amount should be displayed on the row, while the total tax should reflect the sum o ...

Implementing modifications to all HTML elements simultaneously

In my HTML document, there are around 80 small boxes arranged in a grid layout. Each box contains unique text but follows the same structure with three values: name, email, and mobile number. I need to switch the positions of the email and mobile number v ...

Dealing with 'this' while using an addEventListener

I need to trigger the function handleRangeUpdate in a way that it responds to the event calling it and decides whether to run console.log(this.value). The problem arises when I pass e into handleRangeUpdate using addEventListener, causing the value of thi ...

Tips for preventing links from moving when hovering and enlarging text in a navigation menu

I'm looking to design a navigation bar for my website that features various links and the company logo. I want the links to have custom spacing, with some aligned on the left and others on the right edge. Additionally, I would like to incorporate a ho ...

Using SVG background images in Internet Explorer versions 7 and 8: a guide to HTML, CSS,

I have created a unique SVG image to use as a background, but it's not displaying in Internet Explorer 8 and earlier versions. I tried using tools like or http://code.google.com/p/svgweb/, but they only support SVG for IMG and Object elements, not ba ...

The sequence of HTML5 DragDrop Enter and Leave events occur consecutively

I am encountering a problem with a simple drag & drop effect where the class name is changed when the drag enters or leaves, resulting in continuous entering and leaving. Take a look at this basic HTML code: <div class="box"> <div cla ...