javascript - 反应内联样式 - 用居中文本替换 tbody
问题描述
我有一个空数组,我将其转换为 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
解决方案
试试这个代码,只需复制和粘贴。
在这里你可以预览演示:Demo
const [matchEvents, setMatchEvents] = useState([]);
<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 && (
<tbody>
{/* Your Table Body */}
</tbody>
)}
</Table>
{/* Your Error Message */}
{!matchEvents.length && (
<div
style={{
height: "100vh",
display: "flex",
alignItems: "center"
}}
>
<p style={{ width: "100%", textAlign: "center" }}>
No Match Events Yet...
</p>
</div>
)}
</Card>
推荐阅读
- kubernetes - 我可以更详细地查看推出吗?
- python - 在引用列时将函数逐行应用于熊猫数据框
- javascript - 如何从客户端的图像中删除 EXIF?(JS 或 Angular)
- spring-boot - Springboot/Spring Batch 加载不带分隔符的文件
- flutter - 拉动刷新WebView
- python - 使用 Python 从 csv 文件自动创建 BigQuery 架构/表
- android - Flutter:RangeError(索引):无效值:有效值范围为空:0
- javascript - 如何在 React JS 中创建相同的 URL 方案但不同的路由和组件
- php - 我将如何保护 /netdata 或 Laravel 的 Netdata?
- c++ - 将输出流上的“nullptr”格式化为十六进制地址,而不是“0”