I have a flex box and I'd like to make sure that each item has a minimum gap between them. I've found the gap property but when I look up the property on MDN it says it's unsupported in all browsers except Firefox.
It works in Firefox but in Chrome it doesn't appear to.
Is there another CSS property I could use for other browsers or should I stick with margin-right? Could I use both?
#GroupGap {
position: absolute;
width: 349px;
height: 14px;
left: 0;
top: 80px;
display: flex;
flex-direction: row;
align-items: stretch;
justify-content: space-between;
flex-wrap: nowrap;
overflow: visible;
gap: 25px; /* test */
grid-gap: 50px; /* test */
}
#Group {
position: absolute;
width: 349px;
height: 14px;
left: 0;
top: 30px;
display: flex;
flex-direction: row;
align-items: stretch;
justify-content: space-between;
flex-wrap: nowrap;
overflow: visible;
}
/* add animation to class */
.group {
animation: resize 2500ms linear 0s infinite;
}
/* size width transition */
@keyframes resize {
0% {
width: 72%;
}
37.5% {
width: 72%;
}
50% {
width: 50%;
}
87.5% {
width: 50%;
}
100% {
width: 72%;
}
}
/* add margin to group to apply to group items */
.itemGap > * {
margin-right: 25px;
}
/* add margin to group to apply to group items */
.itemGap > *:last-child {
margin-right: 0;
}
/* add outline around group */
.menu {
outline: 1px dashed rgba(0,0,0,.35);
}
#label1 {
position: absolute;
left: 0;
top: 60px;
}
body {
font-family: Arial, sans-serif;
font-size: 11px;
}
<div>Group items with margin right:</div>
<div id="Group" class="menu group itemGap">
<div>
<span>Home</span>
</div>
<div>
<span>Products</span>
</div>
<div>
<span>Products</span>
</div>
<div>
<span>Services</span>
</div>
<div>
<span>About</span>
</div>
<div>
<span>Contact</span>
</div>
</div>
<div id="label1">Group with gap and grid gap:</div>
<div id="GroupGap" class="menu group">
<div>
<span>Home</span>
</div>
<div>
<span>Products</span>
</div>
<div>
<span>Products</span>
</div>
<div>
<span>Services</span>
</div>
<div>
<span>About</span>
</div>
<div>
<span>About</span>
</div>
<div>
<span>About</span>
</div>
<div>
<span>Contact</span>
</div>
</div>
Update:
Using margin right on each item and removing it on the last item seems to work.
/* add a right margin on each item */
.itemGap > * {
margin-right: 25px;
}
/* remove right margin on last item */
.itemGap > *:last-child {
margin-right: 0;
}
https://developer.mozilla.org/en-US/docs/Web/CSS/:last-child https://developer.mozilla.org/en-US/docs/Web/CSS/gap