我希望沿着y轴居中Reaction Bootstrap Table行中的内容.

以下是我目前拥有的代码:

import React from "react";
import { ThreeDots } from "react-bootstrap-icons";

return (
<Table>
  <thead>
    <tr>
      <th>#</th>
      <th>Question</th>
      <th>Answer</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>Define inflation</td>
      <td>Inflation is the rate of increase ...</td>
      <td><ThreeDots/></td>
    </tr>
  </tbody>
</Table>
);

以下是我try 过的:

import React from "react";
import { ThreeDots } from "react-bootstrap-icons";

return (
<Table>
  <thead>
    <tr>
      <th>#</th>
      <th>Question</th>
      <th>Answer</th>
    </tr>
  </thead>
  <tbody>
    <tr className="d-flex align-items-center">
      <td>1</td>
      <td>Define inflation</td>
      <td>Inflation is the rate of increase ...</td>
      <td><ThreeDots/></td>
    </tr>
  </tbody>
</Table>
);

我在<tr>元素的基础上加上了className="d-flex align-items-center".

但是桌子的边框变得乱七八糟,有人知道我能做些什么来解决这个问题吗?


更新

根据Boostrap doc,我发现使用类align-middle可以将表格单元格的内容垂直居中.

有没有人知道有没有一种可以应用于表行或表以使所有行垂直居中的CSS/Bootstrap样式?

推荐答案

下面是您可以用来定义d-flex align-items-center类的CSS代码:

/* Custom CSS */
.d-flex {
  display: flex !important;
}

.align-items-center {
  align-items: center !important;
}

将此CSS代码添加到项目的样式表中.确保将此样式表包括在项目的HTML文件中,以便将定制的CSS规则按预期应用于表格单元格.这将帮助您在表格单元格内实现所需的垂直对齐,同时保留表格的布局和边框.

For the updated question:

要使Bootstrap表中的所有行垂直居中,可以将align-middle类直接应用于<tbody>部分中的<tr>个元素.这将使每行中所有单元格的内容垂直居中.以下是修改代码以实现这一点的方法:

import React from "react";
import { ThreeDots } from "react-bootstrap-icons";

return (
  <Table>
    <thead>
      <tr>
        <th>#</th>
        <th>Question</th>
        <th>Answer</th>
      </tr>
    </thead>
    <tbody>
      <tr className="align-middle">
        <td>1</td>
        <td>Define inflation</td>
        <td>Inflation is the rate of increase ...</td>
        <td><ThreeDots /></td>
      </tr>
      {/* Add more rows here */}
    </tbody>
  </Table>
);

通过将align-middle类添加到<tbody>中的<tr>个元素中,您可以确保所有行的内容在每个单元格中垂直居中.这为表中的所有行提供了一致的垂直对齐方式.

Reactjs相关问答推荐

NextJs Form不允许我输入任何输入,

导致useState中断的中断模式

如何使用皮金贴图在Reactjs中制作 map 上的点之间的线的动画?

使用 MUI 菜单时添加新 html 元素时布局意外滚动跳转

PWA:注册事件侦听器不会被触发

如何在 ChartJS 中创建此图表?在 NEXTjs 和 TSX 中

是的验证:使用 useFieldArray 访问表单值

React Js和Firestore中如何将当前ID与集合中的ID查询以仅显示具有相似字段和值的文档-第二部分

如何在 React 过滤器中包含价格过滤器逻辑?

基于 React/NextJS Timer 的文本淡入/淡出不起作用

如何通过 id 从 useSprings 数组中删除元素

自动重新获取不起作用 - RTK 查询

如何将值从下拉列表传递到 select 上的输入?响应式JS

React 中的 Slide API Mui 在开始而不是结束时触发侦听器

在 Remix 中使用 chartjs 和 react-chartjs-2 会出现错误react-chartjs-2未在您的 node_modules 中找到

如何从一组对象映射 MUI 5 图标并更改其 colored颜色 ?

react-query、react-hook-form 和表单验证

哪个是创建 React 应用程序的更好方法?

Axios 删除在带有授权令牌的react js 中不起作用

调用函数以获取数据并在数据到达时导航到链接