Flex包装和Flex基础不使用CSS工作?

发布于 2025-02-06 15:51:58 字数 1748 浏览 2 评论 0 原文

我正在制作此应用程序,并且正在使用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%,依此类推。

目前,它不起作用。

请帮助我,这将有所帮助! 谢谢。

I am making this application, and I am using React. Here, I have many items, and I am dynamically adding them using React. Here's my code to help you understand better -

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>

Here is a snippet of my items:

  {
    id: 7,
    price: 50,
    button: (
      <button
        onClick={() => {
          alert("This function is not ready yet!!!!");
        }}
      >
        Click!
      </button>
    ),

    title: "Apple",
  },

So, when I run my program, I get this-
My Pic

I had taken another similar code from here

As you can see, the code I had taken from the other stackoverflow is working, but mine is not working. I've used the same technique to do for mine as well but it's not working.

What I want is, 2 of the items to come in a row, with 50% of width, and so on.

Currently, it's not working.

Please help me out, it would help out a ton!
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

手长情犹 2025-02-13 15:51:58

就您的问题而言,删除某些代码将允许它起作用。

.flexContainer .item {
  display: block;
  width: 500px; 
} 

除非您有其他理由将其列入您的代码

, /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.

.flexContainer .item {
  display: block;
  width: 500px; 
} 

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.

玩套路吗 2025-02-13 15:51:58

更改您的物品样式宽度

.flexContainer .item {
  width:50% !important
}

change your item style width

.flexContainer .item {
  width:50% !important
}

仄言 2025-02-13 15:51:58

如果您使用的是Bootstrap,则使用行和两个Col-6类,还可以结帐bootstrap网格的链接

https://getbootstrap.com/docs/5.2/layout/grid/

<div class="container">
  <div class="row">
    <div class="col-6">
      first
    </div>
    <div class="col-6">
      second
    </div>
  </div>
</div>

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/

<div class="container">
  <div class="row">
    <div class="col-6">
      first
    </div>
    <div class="col-6">
      second
    </div>
  </div>
</div>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文