javascript - 如何在反应中显示3行数据?
问题描述
我有 12 个博客如何在反应中显示 3 行宽 4 列的博客片段?我在下面尝试过,但内容只是集中在列中
下面是jsx
{Data.map((item) => {
return (
<div key={item.id} className='div-style'>
<div>
<img src={item.image} alt="img" width='300' height="200"></img>
</div>
<div>
<h2>{item.header}</h2>
</div>
<div>
<p>{item.pargraph}</p>
</div>
</div>
)
})
}
下面是css
.div-style{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
解决方案
您将需要为博客添加一个容器 div(只需在运行数组map()
方法之前添加一个 div),然后您可以更新您的 css,例如:
.div-container {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.div-container>.div-style {
flex: 1 1 20%;
margin: 5px;
height: 50px;
}
.div-style {
background-color: #aaa;
border: 1px solid #777;
}
<div class="div-container">
<div class="div-style">1</div>
<div class="div-style">2</div>
<div class="div-style">3</div>
<div class="div-style">4</div>
<div class="div-style">5</div>
<div class="div-style">6</div>
<div class="div-style">7</div>
<div class="div-style">8</div>
<div class="div-style">9</div>
<div class="div-style">10</div>
<div class="div-style">11</div>
<div class="div-style">12</div>
</div>
推荐阅读
- javascript - 使用 Google 增强型电子商务,在添加/从购物车中删除时,数量值应该代表什么?
- kubernetes - pod.containers.spec.resources 不起作用(限制和请求)Kubernetes
- python - 使用字符串和 python 列表参数从终端运行 shell 脚本
- python - Flask 身份验证和蓝图
- cakephp-3.0 - 在 Web 应用程序中使用 httpClient 会导致错误(cakephp3 App On GCE)
- java - 比较两个列表的内容,Java,Selenium
- sql - SQL - 查找列日期是否至少部分包含日期范围
- qt - QML:没有调用 Rectangle 的 MouseArea 上的 onClicked 方法
- gruntjs - 无法使用 'in' 运算符搜索 'src' Grunt
- artifactory - 无法收集对本地 Artifactory Pypi 存储库的补丁依赖项