簡體   English   中英

為什么我的react-bootstrap模式組件會這樣顯示?

[英]Why my react-bootstrap modal component displays like that?

在開發下一個React應用程序期間,我不得不使用react-bootstrap中的模式組件。 它實際上工作正常,但看起來好像沒有導入樣式表?

這是我的代碼

import React from "react";
import Modal from 'react-bootstrap/Modal';
import Button from 'react-bootstrap/Button';

class Nav extends React.Component {
    constructor(props, context) {
      super(props, context);

      this.handleShow = this.handleShow.bind(this);
      this.handleClose = this.handleClose.bind(this);

      this.state = {
        show: false,
      };
    }

    handleClose() {
      this.setState({ show: false });
    }

    handleShow() {
      this.setState({ show: true });
    }

    render() {
      return (
        <>
          <nav>
            <h5>a pack of free css animations</h5>
            <ul>
             <li><button variant="primary" onClick={this.handleShow}>how to use ></button></li>
              <li>
                <form method="get" action="file">
                 <button type="submit">download ></button>
               </form>
              </li>
              <li><a href=".">see on github ></a></li>
            </ul>
          </nav>

          <Modal
          show={this.state.show}
          onHide={this.handleClose}
          aria-labelledby="ModalHeader"
          >
          <Modal.Header closeButton>
            <Modal.Title id="contained-modal-title-vcenter">How to use?</Modal.Title>
          </Modal.Header>
          <Modal.Body>
            <p>Once you downloaded <i>animation.min.css</i>, you have to link that to your project.<br />
              To do that, use a 'link' tag, or just copy code of animation you like.</p>
          </Modal.Body>
          <Modal.Footer>
            <Button variant="secondary" onClick={this.handleClose}>
                Close
            </Button>
          </Modal.Footer>
        </Modal>
        </>
      );
    }
  }

export default Nav;


看起來像(Chrome) 點擊我


模態顯示在底部,文本未居中等...
你怎么看?
如何改善呢?

從react-bootstrap加載樣式,如下所示:

https://react-bootstrap.github.io/getting-started/introduction/

您從react-bootstrap中丟失了樣式表,這就是為什么模型無法正確設置樣式的原因。 將以下內容添加到您的html中,它應該可以工作。

<link
  rel="stylesheet"
  href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"
  integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"
  crossorigin="anonymous"
/>

請通過鏈接來集成您的應用程序並與react-bootstrap一起使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM