【问题标题】:Bootstrap modal not showing properly centered引导模式未正确居中显示
【发布时间】:2018-11-07 20:20:20
【问题描述】:

screenshot of the page

嗨,我想弄清楚为什么这个模态会这样显示。我遵循的代码是从引导网站复制的。 在这里

<button type="button" class="btn btn-info btn-lg" (click)="showPerformedActivityModal()">Show Performed Activities</button>

<!--Modal -->
<div class="container">
  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true"
  [ngStyle]="{'display': myModalIsOpen ? 'block' : 'none', 'opacity': 5}">
    <div class="modal-dialog modal-dialog-centered" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          <app-table [config]="config" [columns]="columns" [entity]="entity" [sort]="sort" [sortOrder]="sortOrder">
          </app-table>
        </div>

        <div class="modal-footer">
          <button type="button" class="btn btn-primary" (click)="refreshResources()">Select Activities</button>
          <button type="button" class="btn btn-default" (click)="closeModal()">Close</button>
        </div>
      </div>

    </div>
  </div>
</div>

【问题讨论】:

    标签: html modal-dialog bootstrap-4 bootstrap-modal


    【解决方案1】:

    这样就可以了:http://jsfiddle.net/sRmLV/1140/

    您需要使用新的 DIV 和自定义 CSS,将类 'modal-dialog-centered' 更改为 'vertical-align-center'

    HTML

    <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">Launch demo modal</button>
    
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="vertical-alignment-helper">
        <div class="modal-dialog vertical-align-center">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
              <h4 class="modal-title" id="myModalLabel">Modal title</h4>
            </div>
            <div class="modal-body">...</div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
              <button type="button" class="btn btn-primary">Save changes</button>
            </div>
          </div>
        </div>
      </div>
    </div>
    

    CSS

    .vertical-alignment-helper {
    display:table;
    height: 100%;
    width: 100%;
    pointer-events:none;}
    
    .vertical-align-center {
    /* To center vertically */
    display: table-cell;
    vertical-align: middle;
    pointer-events:none;}
    
    .modal-content {
    /* Bootstrap sets the size of the modal in the modal-dialog class, we need to inherit it */
    width:inherit;
    max-width:inherit; /* For Bootstrap 4 - to avoid the modal window stretching 
    full width */
    height:inherit;
    /* To center horizontally */
    margin: 0 auto;
    pointer-events:all;}
    

    【讨论】:

    • 不错的解决方案!它工作正常,你救了我的命! :-)
    猜你喜欢
    • 1970-01-01
    • 2021-03-15
    • 2013-02-24
    • 1970-01-01
    • 1970-01-01
    • 2021-08-09
    • 1970-01-01
    相关资源
    最近更新 更多