简体   繁体   English

Boostrap 4:模式不会显示在我的React应用中

[英]Boostrap 4: Modal won't show on my react app

I am trying to add a modal to my app. 我正在尝试向我的应用添加模式。 I make it so that once my page is loaded, it will show( does not require button) for test purpose. 我这样做是为了使我的页面加载后将显示(不需要按钮)用于测试目的。 I have "bootstrap": "^4.1.3" as my dependency. 我的依赖项为"bootstrap": "^4.1.3"

On my CSS, i make it so that the display is block: 在我的CSS上,我将其显示为阻止状态:

.modal{
  display: block
}

.modal-content{
  display: block
}

In my react app, I import it and use it as follow: 在我的react应用程序中,我将其导入并按以下方式使用:

import 'bootstrap/dist/css/bootstrap.min.css';

  render() {
    return (
      <div className="App">
        <div className="modal fade" id="myModal" role="dialog">
          <div className="modal-dialog">
            <div className="modal-content">
              <div className="modal-header">
                <button type="button" className="close" data-dismiss="modal">&times;</button>
                <h4 className="modal-title">Modal Header</h4>
              </div>
              <div className="modal-body">
                <header className="App-header">
                  Code Authentication
                </header>

                <div className="row">
                  <div className="col-sm-6">
                      {this.getPhoneList()}
                  </div>
                  <div className="col-sm-6">
                      {this.getMethodList()}
                  </div>
                </div>

                <button type="button" className="btn btn-info" onClick={() => this.VerifyCode()}>
                  VERIFY CODE
                </button>
              </div>
              <div className="modal-footer">
              </div>
            </div>

          </div>
        </div>
      </div>
    );
  }

I copied the modal code from boostrap's document and modified a little bit so it works for my test purpose. 我从boostrap的文档中复制了模式代码,并进行了一些修改,使其可以用于我的测试目的。 I also tried many different code, but none of the modal worked. 我也尝试了许多不同的代码,但是这些模式都不起作用。

What I have tried: I have read many of Posts related to this issues on Stack. 我尝试过的内容:我在Stack上阅读了很多与此问题相关的帖子。 Many of them were simply due to the fact that the OP did not include certain file or the attribute of display is not set to show. 其中许多原因仅是因为OP不包含某些文件或未将display属性设置为show。 In my case, i am neither. 就我而言,我都不是。

Any suggestions will be helpful 任何建议都会有帮助

The modal is meant to be shown with a trigger which adds modal-open to the body and show to the modal. 模态旨在与触发器一起显示,该触发器向主体添加modal-open并向模态show To make the modal show remove fade , and add the d-block class which will force the modal to display. 要使模式显示消除fade ,并添加d-block类,它将强制模式显示。

<div className="modal d-block" id="myModal" role="dialog">
          <div className="modal-dialog">
            <div className="modal-content">
...

https://www.codeply.com/go/r47k4BlDKA https://www.codeply.com/go/r47k4BlDKA

I believe that your .fade class has the attribute opacity: 0; 我相信您的.fade类具有opacity: 0;属性opacity: 0; your CSS should be overriding this with opacity: 1; 您的CSS应该用opacity: 1;覆盖opacity: 1;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM