javascript - How make side by side div elements?
问题描述
Hello i have in my react app component with list of events. I would like to display them side by side, not one by one. I was trying to do this with flexbox but something its wrong. Thanks for help.
.flex-container {
display: flex;
}
.place-list {
flex: 1;
margin: 1rem auto;
padding: 0;
width: 100%;
max-width: 20%;
}
return (
<div className="flex-container">
<div className="place-list">
{props.items.map((place) => (
<PlaceItem
key={place.id}
id={place.id}
image={place.image}
title={place.title}
description={place.description}
address={place.address}
creatorId={place.creator}
coordinates={place.location}
onDelete={props.onDeletePlace}
/>
))}
</div>
</div>
);
};
解决方案
弹性容器需要弹性元素的父元素。
你的弹性容器是你想成为弹性元素的元素的祖父母。它只有一个孩子。
具有类的元素place-list
需要输出每个元素,而<PlaceItem>
不是所有元素的单个包装器。
推荐阅读
- c# - 使用反序列化 XML 文件中的多字段 List<> 填充第二个单字段列表 (Xamarin)
- java - JSON 在全选中抛出 java.lang.StackOverflowError
- c# - 在 C# 中使用 Python 库
- javascript - 用于处理日期选择器下拉列表的 JavaScript 对象(三个不同的下拉列表)
- webpack - Webpack 4 - 父文件夹中的 node_modules。如何创建供应商块?
- php - 如果使用 HTML,TCPDF MultiCell 会忽略 valign
- c# - RabbitMQ C# 客户端可扩展?
- apache-spark - Spark shuffle 阻止复制
- rest - 运行在不同 Docker 容器中的 Spring Boot 应用程序拒绝连接
- vim - 在 pipenv 中从 vim ALE 运行 Pylint 和 MyPy 时出现错误的导入错误。-- :!pylint % 有效 -- :!mypy % 有效