Exploring the power of CSS Flexbox and its unique gap properties

\<div class="container-7"\>

\<div class=" box box1"\>\</div\>

\<div class="box box1"\>\</div\>

\<div class="box box1"\>\</div\>

\<div class="box box1"\>\</div\>

\<div class="box box1"\>\</div\>

\<div class="box box1"\>\</div\>

\<div class="box box1"\>\</div\>

\</div\>

.container-7 {

display: flex;

flex-direction: column;

column-gap: 24px;

}

box  {

height: 100px;

flex-basis: calc(25% - 24px);

flex-grow: 1;

flex-shrink: 1

background-color: orchid;

}

I have a total of seven containers. When applying flex basis: calc (25% - 24px), the first four containers are positioned in the first row and the remaining three in the second row. To center the last three containers within the second row, one approach would be to adjust the CSS properties by adding extra styles or classes to the specific elements.

Answer №1

Change the flex-direction property from column to row and enable wrapping, then use justify-content to center the items.

.container-7 {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  /* flex-direction: column; */
  gap: 24px;
}

.box {
  outline: 1px solid grey;
  height: 100px;
  flex: calc(25% - 24px) 0 0;
  background-color: orchid;
}
<div class="container-7">

  <div class="box box1"></div>

  <div class="box box1"></div>

  <div class="box box1"></div>

  <div class="box box1"></div>

  <div class="box box1"></div>

  <div class="box box1"></div>

  <div class="box box1"></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

Having trouble fitting oversized images into Bootstrap columns, attempting to resize them to stay within the column boundaries

Struggling with a challenge in my CMS - figuring out how to allow users to drag images of any size into a bootstrap column/row and have them responsively scale to fit. The goal is to ensure that these images stay within the designated area between a header ...

Adding a button input and deleting non-functional parent elements

Here is a simple append function using jQuery, and it's working perfectly. However, the issue arises when I try to append a button and remove the parent tr upon clicking. The problem lies in using remove parent, as it doesn't seem to work as exp ...

Tips for vertically centering a span within a div that is floated to the right

Need help centering a span vertically within a div when using float:right? <div class="card"> <div class="card-header"> <h5>TEST</h5> <span class="fa fa-info"></span> </div> <div class="card-body" ...

The code `$(body).css({'background-image':'url'}) is not functioning properly

Is it safe to assume that the .css() method cannot be applied to the body tag? Since it seems to work fine when used on $("#div")... ...

CSS creates gaps between each of the internal elements inside the HTML document

I'm looking to create a 4px space between all internal components within my HTML, regardless of direction (top, bottom, left, or right). I have attempted to achieve this by using an external CSS file with the following code: body { padding: 2p ...

What steps can I take to minimize the excessive white space below the footer on my website?

I have been attempting to resolve this issue by using multiple methods, but none of them have successfully fixed it. overflow-x: hidden; min-height: 100%; margin: 0px; https://i.sstatic.net/2ctwo.jpg Code: body: background-color: White; margin: 0px; p ...

Placing an image on the chosen option of a <mat-select> using Angular Material

I have incorporated Angular Material into my Angular 2 project, and I am trying to insert a static image (HTML element) in the selected value of mat-select. Unfortunately, I have been unable to find a solution for this issue. Is there anyone who can ...

What are the steps for positioning the footer at the bottom of the page?

Need help positioning a footer at the bottom of the page? Using the class fixed-bottom causes the footer to overlap the content when scrolling. <div class="sticky-top"> <qipr-header></qipr-header> <qipr-sidenav>&l ...

Is there a simple way to set the form inputs to right-to-left without excessive duplication?

Is there a way to apply the right-to-left (RTL) direction to a form without duplicating code for every input, based on the locale of the language being used? Can the locale be changed in CSS to make the form RTL more efficiently? For example: <div ...

creating a css style for a drop shadow effect

I am trying to achieve a shadow effect without displaying the square itself. Here is the block of code I have been working with: .light-blur-effect { height: 100px; width: 100px; background-color: #BEEEF5; opacity: 0.4; filter: drop-sha ...

Troubleshooting problem with div width in Outlook causing table cell padding issue for curved corners on another div

This question has significantly evolved following additional testing I am using a table layout similar to this: <table> <tr> <td></td> <td style="padding:10px 3%;"> <div border="2px solid #000000;"> ...

Tips for increasing the size of the SVG icon within Material UI iconButtons

Have you experimented with creating webpages using react.js along with the Material UI library? How can I adjust the size of an SVG icon? Recently, I developed a "create new" component, which consists of a material paper element with an add button on top. ...

Troubleshooting: Why are my Angular 8 Carousel Slide Animations not functioning

Looking to create a carousel slideshow with images sliding from right to left and smoothly transition to the next image. All the necessary code can be found in this STACKBLITZ Here is the HTML snippet: <ngb-carousel *ngIf="images" [showNavigationArro ...

Designing a website using HTML and CSS with the goal of optimizing it to fill

My website includes all the recommended elements in the head area: <meta charset="utf-8"/> <meta http-equiv="X-UA-Compatible" content="IE=edge"/> <meta name="viewport" content="width=device-width, ...

Implementing the IF statement in jQuery

I've been trying to implement an overflow check when hovering over a div. The issue arises because I'm using jQuery for the hover function and then simple JavaScript for the overflow check in the next step. It seems that directly using an if-then ...

What is the best way to trigger a function with a bootstrap toggle?

A toggle switch has been implemented using bootstrap with the following code snippet: <label > Automatic Refresh: </label> <input class="pull-right" data-size="mini" type="checkbox" data- toggle="toggle"> When the toggle button is in ...

Uniform Image Sizes in Bootstrap Carousel (With One Exception)

I am encountering a JavaScript exception related to image size. I am trying to set a fixed size for the images in my carousel, allowing them to auto adjust or resize without concern for distortion or pixelation. I have experimented with max-width and widt ...

Inquiring about browserify or webpack on a website using node - a few queries to consider

Seeking assistance with a website project I am currently working on. The project consists of 7 HTML documents, 3 stylesheets, 8 JavaScript files (including jQuery.min.js and some additional jQuery plugins), and various images. I am looking to bundle and mi ...

What is the Best Way to Align a Float Element Perfectly in the Middle of Two Other Floated Elements?

I've encountered a challenge in centering text between two other texts. My Code: <div class="main-container"> <div class="footer"> <span class="left_edge">@left</span> <span class="center">@center< ...

Use jQuery to swap out every nth class name in the code

I am looking to update the 6th occurrence of a specific div class. This is my current code <div class="disp">...</div> <div class="disp">...</div> <div class="disp">...</div> <div class="disp">...</div> < ...