React Bootstrap 中的模态标题和按钮居中

aga*_*eja 4 reactjs react-bootstrap

我正在尝试为我的项目实现 React Modal。我想将模态标题和模态按钮居中。我尝试使用 flex 和 just-content-center 但它不起作用。任何建议都很有价值。

<Modal show={modalShow} onHide={this.handleClose} aria-labelledby="contained-modal-title-vcenter" centered>
    <Modal.Header closeButton>
        <div className="d-flex justify-content-center">
            <Modal.Title>{isVerified?"Submitted succesfully":"Failed to submit"}</Modal.Title>
        </div> 
    </Modal.Header>
         <Modal.Footer>
    <Button variant={`${isVerified == false?"danger ":"success"}`} onClick={this.handleClose} centered>
        {isVerified?"Ok":"Try again"}
    </Button>
    </Modal.Footer>
</Modal>
Run Code Online (Sandbox Code Playgroud)

小智 5

我尝试了不同的课程,但有效的是:

import React from "react";
import { Modal, Button } from "react-bootstrap";

const ModalPage = ({ modalShow, handleClose, isVerified }) => {
  return (
    <Modal
      show={modalShow}
      onHide={handleClose}
      aria-labelledby="contained-modal-title-vcenter"
      centered
    >
      <Modal.Header
        closeButton
        style={{
          display: "flex",
          justifyContent: "center",
          alignItems: "center",
        }}
      >
        <Modal.Title>
          {isVerified ? "Submitted succesfully" : "Failed to submit"}
        </Modal.Title>
      </Modal.Header>          
      <Modal.Footer
        style={{
          display: "flex",
          justifyContent: "center",
        }}
      >
        <Button
          variant={`${isVerified == false ? "danger " : "success"}`}
          onClick={handleClose}
          centered
        >
          {isVerified ? "Ok" : "Try again"}
        </Button>
      </Modal.Footer>
    </Modal>
  );
};

export default ModalPage;
Run Code Online (Sandbox Code Playgroud)