【发布时间】:2021-03-29 17:46:03
【问题描述】:
JS代码
import React from 'react';
import styles from './CountriesTable.module.css';
const CountriesTable = ({ countires }) => {
...
return (
<div className='table'>
<Row>
{countries.map((country) => (
<Col xs="12" sm="6" lg="4">
<Card className={styles.card}>
<CardImg className={styles.icon} src={country.flag} alt={country.name} />
<CardBody className={styles.body}>
<CardTitle tag="h5">{country.name}</CardTitle>
<div className='tag'>
{country.languages.map(({ name }) => (
<Badge color="secondary" pill>{name}</Badge>
))}
</div>
<CardText>Test text message here</CardText>
</CardBody>
</Card>
</Col>
))}
</Row>
</div>
)
}
...
export default CountriesTable;
CSS
.row {
display: flex;
flex-wrap: wrap;
flex: 1 1 auto;
margin-right: -12px;
margin-left: -12px;
}
.card {
display: flex;
flex-wrap: wrap;
align-items: stretch;
justify-content: space-around;
padding: 8px;
text-align: left;
width: 100%;
height: 90%;
background-color: var(--background-color-light);
border-radius: 8px;
margin-bottom: 10px;
box-shadow: var(--box-shadow);
font-weight: 500;
transition: transform 200ms ease-in-out, box-shadow 200ms ease-in-out;
cursor: pointer;
}
.icon {
display: flex;
align-items: center;
justify-content: center;
width: 70px!important;
min-width: 70px;
margin-right: 4px;
}
.icon img {
border-radius: 2px;
width: 100%;
}
.body {
flex: 1;
align-items: center;
font-weight: 500;
font-size: 16px;
text-align: left;
}
.price {
text-align: right;
margin-bottom: 8px;
}
我正在使用 Reactstrap (https://reactstrap.github.io/) 在 React 中使用 Bootstrap。
我正在努力适应左侧的标志,以及每张卡片右侧的其余内容。目前,我面临两个问题:
-
某些卡片内容超出右侧的卡片边界。
-
对于某些卡片,旗帜等内容仍然是垂直展开的。
我是 CSS 和 React 的新手。非常感谢您提前提供任何建议!
【问题讨论】:
-
给我一点时间。 Mate :) 让我先安装 reactstrap 来看看这个。现在尝试从代码中删除内联样式。我的意思是这些 className={styles.card},className={styles.icon} 和 className={styles.body}。直接用 className="body" 替换那些,其他人也类似
-
您的国家/地区数组对象是什么样子的。在此处共享 1 个对象以进行测试
-
@ImranRafiqRather 谢谢!这是 api 的链接:restcountries.eu/rest/v2/all
-
我认为现在可以正常工作了,您现在只需要为国家/地区集成 API 即可。试一次。如果您遇到困难,我只在这里:) ...
标签: css reactstrap