BsDatePicker隐藏在模态后面

问题描述

<!-- The Server Modal -->
<div class="modal" id="serverModal">
    <div
        class="modal-dialog"
        style="max-width: 80%;overflow-y: initial !important;"
    >
        <div class="modal-content">
            <!-- Modal Header -->
            <div class="modal-header">
                <h4 class="modal-title">
                    User # {{ globals.currentUser }}
                </h4>
            </div>

            <!-- Modal body -->
            <div
                class="modal-body"
                style="max-height: calc(100vh - 200px);
    overflow-y: auto;"
            >
                <table class="table table-striped table-bordered">
                    <tbody>
                        <tr>
                            <td>
                                <div class="row">
                                    <div class="col-6" style="width:150px;">
                                        ObsoleteServerActionDate
                                    </div>
                                    <div class="form-group col-6">
                                        <input
                                            type="text"
                                            placeholder="DOJ"
                                            class="form-control"
                                            bsDatepicker
                                            [bsConfig]="{
                                                dateInputFormat: 'MM/DD/YYYY',containerClass: 'theme-dark-blue' 
                                            }"
                                        />
                                    </div>
                                </div>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <!-- Modal footer -->
            <div class="modal-footer">
                <button
                    type="button"
                    class="btn btn-primary"
                    data-dismiss="modal"
                    (click)="SaveServer()"
                >
                    Save
                </button>
                <button
                    type="button"
                    class="btn btn-danger"
                    data-dismiss="modal"
                    (click)="CancelServer()"
                >
                    Cancel
                </button>
            </div>
        </div>
    </div>
</div>


模态内的表中有一个bsDatePicker。当我打开模式时,日期选择器只是隐藏在模式后面。

我通过为z-index输入元素提供一个类并设置其bsDatePicker来尝试z-index: 3000 !important解决方案,但是它仍然显示在模式后面。为什么要这样做?

解决方法

我想您需要将z-index设置为容器元素。您应该改为这样做:

.theme-dark-blue {
   z-index: 3000 !important;
}

由于它具有config属性,因此您可以利用它:

[bsConfig]="{ dateInputFormat: 'MM/DD/YYYY',containerClass: 'theme-dark-blue show-at-top' }"

.show-at-top{
   z-index: 3000 !important;
}
,

在输入元素的父链中,您需要将css position:relative赋予第一个td

代码中输入元素下方的父元素必须带有position:relative

<input type="text"
                                placeholder="DOJ"
                                class="form-control"
                                bsDatepicker [bsConfig]="{ dateInputFormat: 'MM/DD/YYYY',containerClass: 'theme-dark-blue' }">

我曾经通过在父链的第一个td元素中解决此问题