gpt4 book ai didi

CSS display: flex pushing children up beyond parent's top(Css显示:Flex将孩子推到父母的顶端之外)

转载 作者:bug小助手 更新时间:2023-10-24 19:39:12 25 4
gpt4 key购买 nike



I want a container class that will arrange children from left to right and from top to bottom.

我想要一个容器类,将从左到右,从上到下安排孩子。


I don't want my container to spill outside of the parent's inner box.

我不想让我的容器洒到父母的内盒外面。


If children take up more space than that I want a vertical scroll bar so that I can see all the children if I want to.

如果孩子占据的空间比这个多,我想要一个垂直滚动条,这样我就可以看到所有的孩子,如果我想的话。


I defined .wrap-container like so:

我按如下方式定义了.work-tainer:


.wrap-container {
display: flex;
flex-wrap: wrap;
align-content: center; // vertically
align-items: flex-start; // horizontally
// justify-content: space-between; /* Space items evenly along the main axis */
padding: 15px;
gap: 15px;
margin: 0px;
border: solid blue 1px;
// height: calc(100% - 30px);
// width: calc(100% - 30px);
max-height: calc(100% - 30px);
max-width: calc(100% - 30px);
overflow: auto;
}

It arranges them correctly, but it does not handle the overflow as it should. I can never see the top of the first row of children.

它正确地排列了它们,但没有按其应该的方式处理溢出。我永远看不到第一排孩子的顶端。


To clarify, I know display: flex is allowed to spill outside of the parent, hence

为了澄清,我知道DISPLAY:Flex被允许溢出到父级之外,因此


max-height: calc(100% - 30px); 
max-width: calc(100% - 30px);

The 30px is to account for the parent's padding.
Which, by the way, seems like a bug as well - you would think that specifying max-height: 100% should do it, but no, you need to know how the parent is defined, which seems wrong.

30px将考虑到父母的填充。顺便说一句,这似乎也是一个错误--您可能认为指定max-Height:100%就可以做到这一点,但是不,您需要知道父对象是如何定义的,这似乎是错误的。


But in any case, even if I arrange .wrap-container to not spill outside of its parent, it still does not handle the children correctly.
Please see what I mean here:

https://stackblitz.com/edit/stackblitz-starters-gwqxpg?file=src%2Fapp%2Fapp.component.scss

但是在任何情况下,即使我安排.print-tainer不溢出它的父容器,它仍然不能正确地处理子容器。请明白我在这里的意思:https://stackblitz.com/edit/stackblitz-starters-gwqxpg?file=src%2Fapp%2Fapp.component.scss


The parent of .wrap-container is defined like so:

.work-tainer的父级定义如下:


.parent {
display: block;
width: 500px;
height: 200px;
border: solid red 1px;
padding: 15px;
gap: 15px;
margin: 70px;
}

and children of .wrap-container like so:

而.work-tainer的子容器如下所示:


.child {
border: 1px solid transparent;
border-image-slice: 1;
box-shadow: 0 0 4px 0 rgba(0, 0, 0, 0.5);
padding: 5px;
width: 150px;
height: 100px;
}

It then looks like this:

然后它看起来是这样的:


enter image description here


Even scrolled all the way up you can't see "It's working 1" or "It's working 2".

即使一直向上滚动,你也看不到“It‘s Working 1”或“It’re Working 2”。


更多回答

Just for your information: // is not a valid way to do comments in CSS. This will lead to problems.

仅供参考://不是在css中进行注释的有效方式。这将导致问题。

优秀答案推荐

You should remove the 'align-content: center;' from '.wrap-container'

Setting 'align-content: start' will also work.

您应该从“.print-tainer”中删除“Align-Content:Center;”设置“Align-Content:Start”也可以。


更多回答

Thank you. Do you know why? According to this: developer.mozilla.org/en-US/docs/Web/CSS/align-content it should have helped but it broke it???

谢谢。你知道为什么吗?根据developer.mozilla.org/en-US/docs/Web/CSS/align-content的说法:它本应该帮助你,但它却打破了它?

I'm also learning myself so not sure, but since the container has the 'max-height' value and 'align-content' it must be displaying the content in the center. I'm sure it would also work if you set the 'align-content' to 'start'.

我也在学习自己,所以不确定,但因为容器有‘max-Height’和‘Align-Content’的值,所以它一定是在中间显示内容。我确信,如果您将“Align-Content”设置为“Start”,它也会起作用。

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