-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix: Space组件在 justify="center" 布局下最后一个元素有布局错误 #6995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 9 commits
44a75c4
3fbe174
a71a9dd
6a4811f
398f75b
585573e
db7ed93
6fe31bf
3e79a6a
c8c7812
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,12 +25,18 @@ | |
| } | ||
| > .@{class-prefix-space}-item { | ||
| margin-right: var(--gap-horizontal); | ||
| &:last-child { | ||
| margin-right: 0; | ||
| } | ||
| } | ||
| &.@{class-prefix-space}-wrap { | ||
| flex-wrap: wrap; | ||
| margin-bottom: calc(var(--gap-vertical) * -1); | ||
| > .@{class-prefix-space}-item { | ||
| padding-bottom: var(--gap-vertical); | ||
| &:last-child { | ||
| padding-bottom: 0; | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
26
to
38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 虽然移除最后一个元素的 一个更现代、更健壮的方案是直接在 flex 容器上使用 建议考虑将这部分重构为使用 .@{class-prefix-space}-horizontal {
flex-direction: row;
column-gap: var(--gap-horizontal); // 水平间距
&.@{class-prefix-space}-wrap {
flex-wrap: wrap;
row-gap: var(--gap-vertical); // 换行后的垂直间距
}
}这样就可以移除所有在 |
||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这部分修改会为换行布局引入新的 bug。
:last-child选择器只会匹配最后一个子元素。如果启用了wrap并且最后一行有多个元素,那么只有最后一个元素(即整组元素的最后一个)的padding-bottom会被移除,导致最后一行内的元素垂直方向无法对齐。实际上,父容器上的
margin-bottom: calc(var(--gap-vertical) * -1)已经正确地处理了最后一行多余的padding-bottom,它通过负外边距将整个容器的底部“拉上来”,从而抵消了最后一行的内边距。因此,这里的修改是不必要的,并且是有害的,应当移除。