Ask Your Question
1

What is the method to create a flex box that has a maximum of 2 elements per row?

asked 2022-01-02 11:00:00 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-07-05 12:00:00 +0000

ladyg gravatar image

To create a flexbox with a maximum of 2 elements per row, you can use the CSS properties display: flex and flex-wrap: wrap. Then, set the width of each element to be 50% so that only two elements can fit on each row. Here's an example:

HTML:

<div class="flex-container">
  <div class="flex-item">Item 1</div>
  <div class="flex-item">Item 2</div>
  <div class="flex-item">Item 3</div>
  <div class="flex-item">Item 4</div>
  <div class="flex-item">Item 5</div>
</div>

CSS:

.flex-container {
  display: flex;
  flex-wrap: wrap;
}

.flex-item {
  width: 50%;
  text-align: center;
}

This will create a flexbox with two items per row, and each item will take up 50% of the width of the container. You can adjust the width and other styles as desired to fit your specific design.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-01-02 11:00:00 +0000

Seen: 18 times

Last updated: Jul 05 '21