【问题标题】:How can I style map items to display in justify-content-around?如何设置地图项的样式以在 justify-content-around 中显示?
【发布时间】:2020-09-13 13:36:03
【问题描述】:

我通过映射产品来循环访问它们,而 justify-content-around 不适用于它们,我在我的 react 项目中使用 bootstrap 4。

这是我的代码:

{props.products.map((item) => {
                if (item.inCart) {
                    return (
                        <div className="d-flex justify-content-around w-100" key={item.id}>
                            <button>remove</button>
                            <div>
                                <h5>{item.name}</h5>
                            </div>
                            <div>
                                <h5>{item.price.toLocaleString('ar-EG')}</h5>
                            </div>
                            <div>
                                <h5>{item.number.toLocaleString('ar-EG')}</h5>
                            </div>
                            <div>
                                <h5>{(item.number * item.price).toLocaleString('ar-EG')}</h5>
                            </div>
                            <hr />
                        </div>
                    );
                }

显示 flex 类适用,但不是另一个,它们之间没有边距。

如何让它们显示 justify-content-around ??

【问题讨论】:

标签: javascript css reactjs twitter-bootstrap


【解决方案1】:

您的问题来自&lt;hr&gt; 标签。我刚刚通过this repro on stackblitz 发现了它。 删除它就可以了

如果你真的需要它,那就重新使用它吧:

const Divider = () => {
  return <div className="border-bottom" />;
};

这个依赖于引导程序,但您当然可以轻松地使其通用。你只需要将它应用到你的 flex 容器之外:

<>
  <div className='d-flex justify-content-around' key={item.id}>
    <button>remove</button>
    <h5>{item.name}</h5>
    <h5>{item.name}</h5>
    <h5>{item.name}</h5>
  </div>
  <Divider />
</>;

【讨论】:

    猜你喜欢
    • 2020-09-23
    • 2020-11-15
    • 1970-01-01
    • 2017-04-26
    • 1970-01-01
    • 1970-01-01
    • 2017-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多