Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding space between flexbox items

Tags:

html

css

flexbox

I'm trying to create a horizontally scrollable div with flexbox. So far, I have most of it. However, the only problem I am facing is that I'm trying to add space to my items, but for some reason, nothing seems to be working. I've tried adding margin, padding, justifying content, etc. Here's a jsfiddle of what I'm trying to achieve.

    .grid {
      display: -webkit-flex;
      display: -ms-flexbox;
      display: flex;
      margin-bottom: 20px;
      justify-content: space-between;
    }
    
    /*Each item is one column*/
    
    .item {
      width: 50%;
    }
    
    .article-scroll-mobile {
      box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
      flex-wrap: nowrap;
      text-align: center;
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
      /*For iOS smooth scroll effect*/
    }
 <div class="grid article-scroll-mobile">
      <div class="item">
        <img src="https://www.w3schools.com/howto/img_fjords.jpg">
      </div>
      <div class="item">
        <img src="https://www.w3schools.com/howto/img_fjords.jpg">
    
      </div>
      <div class="item">
        <img src="https://www.w3schools.com/howto/img_fjords.jpg">
    
      </div>
      <div class="item">
        <img src="https://www.w3schools.com/howto/img_fjords.jpg">
    
      </div>
      <div class="item">
        <img src="https://www.w3schools.com/howto/img_fjords.jpg">
    
      </div>
      <div class="item">
        <img src="https://www.w3schools.com/howto/img_fjords.jpg">
    
      </div>
    </div>
like image 812
user2896120 Avatar asked Mar 16 '18 21:03

user2896120


People also ask

How do I add space between items in Flexbox?

To set space between the flexbox you can use the flexbox property justify-content you can also visit all the property in that link. We can use the justify-content property of a flex container to set space between the flexbox.

Can you use gap with Flexbox?

As you see, the gap works perfectly for both CSS grid and flex - on the browsers that support them.

Can you add padding Flexbox?

When it comes to CSS Flexbox, there are a few different ways to add padding. The first way is to use the padding property. This will add padding to the top, right, bottom, and left sides of an element. The second way is to use the padding-top, padding-right, padding-bottom, and padding-left properties.


1 Answers

There is column-gap to adjust row gaps between elements.

.form-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: stretch;
  column-gap: 0.875rem;
}
like image 138
Athena Chen Avatar answered Nov 15 '22 23:11

Athena Chen