【发布时间】:2021-11-08 06:11:54
【问题描述】:
我有一个空数组,我将其转换为 React 中的状态。当未填充数组时,我想在react-bootstrap 表的tbody 中添加一条“还没有匹配事件...”的文本。
图像是它的外观 - 我不确定如何将文本居中在 Card 的中间。
const [matchEvents, setMatchEvents] = useState([]);
return (
<Card>
<Table size="sm">
<thead>
<tr>
<th style={{ width: "33.33%" }}>Event</th>
<th style={{ width: "33.33%" }}>Time</th>
<th style={{ width: "33.33%" }}>Period</th>
</tr>
</thead>
{matchEvents.length !== 0 ? (
<tbody>
{
//Irrelevant code for mapping object to table in here
}
</tbody>
) : (
<tbody>
<tr>
<td />
<td
style={{
display: "flex",
position: "absolute",
}}
>
No Match Events Yet...
</td>
<td />
</tr>
</tbody>
)}
</Table>
</Card>
);
我尝试添加 <tr> 和 <td> 作为顶部的填充符,以使文本进入卡片的中心,但我得到了几行作为边框,无法用 !important 覆盖它们出于某种原因。
【问题讨论】:
-
你想让文字在卡片上垂直居中吗?
-
@AbdullahKhan 是的,如果可能的话,请在中间!
-
添加了答案请试一试...
标签: javascript css reactjs react-bootstrap inline-styles