Flex包装和Flex基础不使用CSS工作?
我正在制作此应用程序,并且正在使用React。在这里,我有很多项目,我正在使用React动态添加它们。这是我的代码可以帮助您更好地理解
-CSS:
.flexContainer {
display: flex;
flex-wrap: wrap;
}
.flexContainer .item {
padding: 5px;
border: 1px solid aqua;
flex: 1 1 50%;
}
.flexContainer .item {
display: block;
width: 500px;
text-align: center;
}
* {
box-sizing: border-box;
}
REACT:
<div class="flexContainer">
<div key={p.id} class="item">
<div class="item">
<p className="itemTitle">{p.title}</p>
<button onClick={() => addItem(p)}>
{alreadyAdded ? "Add again" : "Add to Cart"}
</button>
</div>
</div>
</div>
这是我项目的片段:
{
id: 7,
price: 50,
button: (
<button
onClick={() => {
alert("This function is not ready yet!!!!");
}}
>
Click!
</button>
),
title: "Apple",
},
因此,当我运行程序时,我会得到这个 - 我的pic
我从在这里
如您所见,我从其他stackoverflow中获取的代码是工作,但我的工作不起作用。我也使用了相同的技术来为我做的,但它行不通。
我想要的是,有2个连续的项目,宽度为50%,依此类推。
目前,它不起作用。
请帮助我,这将有所帮助! 谢谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
就您的问题而言,删除某些代码将允许它起作用。
否
除非您有其他理由将其列入您的代码
, /1/“ rel =” nofollow noreferrer”> https://jsfiddle.net/ct96dl2o/1/
因此,从您提供的原始代码中,您提供的答案将有效,如果您需要更精致的答案,则需要显示您需要显示的答案更多代码。
in terms of your question for that row removing some of the the code will allow this to work.
This code is not really needed unless you have other reasons for it to be in your code but doesnt really play part of your question
As you will see from this link your row works
https://jsfiddle.net/ct96dL2o/1/
so from the original code you supplied this answer will work if you need a more elaborate answer you would need to show more code.
更改您的物品样式宽度
change your item style width
如果您使用的是Bootstrap,则使用行和两个Col-6类,还可以结帐bootstrap网格的链接
https://getbootstrap.com/docs/5.2/layout/grid/
If you are using bootstrap then use row and inside of that and two col-6 class and also checkout link of bootstrap grid
https://getbootstrap.com/docs/5.2/layout/grid/