gpt4 book ai didi

html - gap 属性显示它在 MDN 上不受支持。使用安全吗?

转载 作者:行者123 更新时间:2023-11-28 09:15:24 24 4
gpt4 key购买 nike

<分区>

我有一个 flex 盒子,我想确保每个元素之间的间隙最小。我找到了 gap属性,但是当我在 MDN 上查找该属性时,它说它在除 Firefox 之外的所有浏览器中不受支持。

它在 Firefox 中有效,但在 Chrome 中似乎无效。

是否有其他 CSS 属性可以用于其他浏览器,或者我应该坚持使用 margin-right?我可以同时使用两者吗?

#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>

更新:
在每个元素上使用 margin right 并在最后一个元素上删除它似乎有效。

/* 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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com