如何使物品按订单占据空间
我有一个HTML,此HTML有两个儿童的HTML。在父母的html上,我有一个名为.page的Div,这是孩子需要占用的大区域。两个孩子的大小都相同,我需要他们按顺序产卵。因此,假设第一个儿童组件将在1位置产生(如下图中),而另一个孩子的组件则需要遵循订单,如果左边有空间,则可以占用下面的空间左边的元素?
需要如何:
现在如何工作:
CSS:
.page {
display: flex;
width: 26.4cm;
height: 37cm;
flex-wrap: wrap;
align-content: flex-start;
overflow: hidden;
}
儿童网格:
.displayGridSlip {
display: grid;
width: 13cm;
grid-template-columns: 13cm;
grid-template-rows: 1.7cm 4.9cm 0.5cm;
grid-template-areas:
"h"
"b"
"f";
border-bottom-style: dashed;
border-bottom-width: 0.3mm;
border-right-style: dashed;
border-right-width: 0.3mm;
padding-top: 0.2cm;
}
主HTML代码
<div *ngFor="let itemCapa of arraySlips.capa; let k = index;">
<div class="page">
<app-slip-capa [itemCapa]="itemCapa"></app-slip-capa>
<app-slip-conteudo [item]="arraySlips.info" [itemCapa]="itemCapa"></app-slip-conteudo>
</div>
</div>
I have a html and this HTML has two childrens' HTML. On the parent HTML I have a div called .page that's a big area where the children need to occupy. Both children have the same size, and I need them to spawn in a order; so let's say the first child component will spawn in the 1 position (like in the image below), and the other need to follow the order, if has space on the left to occupy, then does it, if not, occupy the space below the element on the left?
How needs to be:
How is working right now:
The CSS:
.page {
display: flex;
width: 26.4cm;
height: 37cm;
flex-wrap: wrap;
align-content: flex-start;
overflow: hidden;
}
Children's grid:
.displayGridSlip {
display: grid;
width: 13cm;
grid-template-columns: 13cm;
grid-template-rows: 1.7cm 4.9cm 0.5cm;
grid-template-areas:
"h"
"b"
"f";
border-bottom-style: dashed;
border-bottom-width: 0.3mm;
border-right-style: dashed;
border-right-width: 0.3mm;
padding-top: 0.2cm;
}
Main html code
<div *ngFor="let itemCapa of arraySlips.capa; let k = index;">
<div class="page">
<app-slip-capa [itemCapa]="itemCapa"></app-slip-capa>
<app-slip-conteudo [item]="arraySlips.info" [itemCapa]="itemCapa"></app-slip-conteudo>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为,在 *ngfor的一个错误之后,使用Div中的.page类是错误的,因为这样您就将所有26厘米宽度用于每个元素,而不是其中的一半。
我不确定这是您要寻找的答案,但请尝试在Div树的开头使用.page,然后在 *ngfor div上使用Col-6,以便仅使用每个元素的列宽度的一半:
另外,我不确定使用厘米是否正确(请参阅此答案: https://stackoverflow.com/a/a/16297686/8003673 ),但请根据需要尝试。如果是错误的,请尝试使用其他维度。
如果您尝试以下代码之类的内容,则使用每个元素的页面维度的一半来工作:
I think that using the .page class in the div after the *ngFor one is wrong because in this way you are using all the 26cm width for each element and not half of that.
I'm not sure this is the answer you are looking for but try using .page at the start of the div tree and then col-6 on the *ngFor div so that it will use only half of the the column width for each element:
Also, i'm not sure that using centimeters is correct (see this answer about that: https://stackoverflow.com/a/16297686/8003673 ), but try as you want. If it's wrong, try using other dimension.
If you try something like the code below, it will work as you want, using half of the page dimension for each element: