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>
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.
As you see, the gap works perfectly for both CSS grid and flex - on the browsers that support them.
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.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With