在flexbox中的儿童中显示儿童中的项目
我有三个CSS课程:.home,.products和.Item。
基本上,.home上的所有组件都应在这样的列中显示:
Home
Products
Button
Something else
虽然.Frouducts中的所有内容都应顺序显示:
Products
Item01 Item02 Item03 Item04
Item05 Item06 Item07 Item...
但是我尝试了很多,但我无法将其作为所需的输出,这些项目始终垂直或水平显示不同的情况。
如果我在列中删除包装div项目的产品,但是如果我添加一个按钮,我希望它显示在所有项目下方,而不是像列表中的项目列表一样。
如果我添加包装div,则这些项目总是在连续显示或喜欢
A
B
C
D
.Home {
display: flex;
flex-direction: column;
flex-wrap: nowrap;
justify-content: flex-start;
align-items: stretch;
align-content: stretch;
}
.Products {
display: flex !important;
flex-direction: row !important;
width: 100% !important;
height: 100px;
color: white;
}
.Item {
margin-right: 3%;
/* start: added by editor for visualization purpose */
min-height: 75px;
border: 2px dashed red;
display: flex;
justify-content: center;
align-items: center;
background-color: gray;
/* end: added by editor for visualization purpose */
}
<div class="Home">
<section class="Products">
<div class="Item">1</div>
<div class="Item">2</div>
<div class="Item">3</div>
<div class="Item">4</div>
<div class="Item">5</div>
<div class="Item">6</div>
<div class="Item">7</div>
<div class="Item">8</div>
</section>
<div>
<button>Add Product</button>
</div>
</div>
任何帮助都将不胜感激,我很难过,并且从未与Flexbox这样的问题
I have three css classes: .Home, .Products, and .Item.
basically all components on the .Home should display in a column like this:
Home
Products
Button
Something else
While everything in .Products should display sequentially like this:
Products
Item01 Item02 Item03 Item04
Item05 Item06 Item07 Item...
However I have tried a lot and I cannot get this to be the desired output the items always display vertically or horizontally in different situations.
If I delete the products wraping div the items display in a column, but if I add a button I want it to display below all of the items and not with the item list like it is apart of the list.
if I add the wrapping div then the items always display in a row or like
A
B
C
D
.Home {
display: flex;
flex-direction: column;
flex-wrap: nowrap;
justify-content: flex-start;
align-items: stretch;
align-content: stretch;
}
.Products {
display: flex !important;
flex-direction: row !important;
width: 100% !important;
height: 100px;
color: white;
}
.Item {
margin-right: 3%;
/* start: added by editor for visualization purpose */
min-height: 75px;
border: 2px dashed red;
display: flex;
justify-content: center;
align-items: center;
background-color: gray;
/* end: added by editor for visualization purpose */
}
<div class="Home">
<section class="Products">
<div class="Item">1</div>
<div class="Item">2</div>
<div class="Item">3</div>
<div class="Item">4</div>
<div class="Item">5</div>
<div class="Item">6</div>
<div class="Item">7</div>
<div class="Item">8</div>
</section>
<div>
<button>Add Product</button>
</div>
</div>
any help would be appreciated, I am stumped and have never had an issue like this with flexbox
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您希望您的项目出现在多行上,则需要将
flex-wrap
设置为wrap
,并给出每个项目flex-basis < /code>,或
最小宽度
If you want your items to appear on multiple rows, then you would need to set
flex-wrap
towrap
and give each of your items aflex-basis
, ormin-width
您可以触摸标记吗?并添加一个线路(在您希望线路断路的任何弹性项目之后)。添加
&lt; div class =“ line-break”&gt;&lt;/div&gt;
在您想要链接中断的项目之后,此css.line-break {width {width:100%;可见性:隐藏;}
和flex-flow:row wrap;
to.products
或使用
网格
,它总是可以进行这种布局。Can you touch the markup? And add a line break (after whatever flex item you want the line to break). Add
<div class="line-break"></div>
after the item you want link break, this css.line-break {width: 100%; visibility: hidden;}
and aflex-flow: row wrap;
to.Products
Or use
grid
which is always a go to approach for such kind of layouts.你几乎在那里。您必须向父添加
Flex-wrap
并计算卡片的正确宽度(项目)。请参阅CSS中的评论以获取进一步的参考:YOu where nearly there. You had to add
flex-wrap
to the parent and to calculate the correct width of the cards (item). See the comments within CSS for further reference: