【问题标题】:BsDatePicker hiding behind modal隐藏在模态后面的 BsDatePicker
【发布时间】:2020-12-21 12:59:12
【问题描述】:
<!-- 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,但它仍然显示在模式后面。为什么要这样做?

【问题讨论】:

    标签: javascript css bootstrap-4 bootstrap-modal bootstrap-datetimepicker


    【解决方案1】:

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

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

    因为它有一个配置属性,你可以利用它:

    [bsConfig]="{ dateInputFormat: 'MM/DD/YYYY', containerClass: 'theme-dark-blue show-at-top' }"
    
    .show-at-top{
       z-index: 3000 !important;
    }
    

    【讨论】:

    • 感谢您的回答。不幸的是,它仍然不起作用。
    • 如果你应用这种风格会发生什么?你也可以发一下吗?目标元素是否应用了这个 css 类?
    • css 类 'theme-dark-blue' 没有被应用。有没有我应该包含的 css 文件?
    【解决方案2】:

    在输入元素的父链中,你需要将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 元素中解决了这个问题

    【讨论】:

      猜你喜欢
      • 2013-10-05
      • 1970-01-01
      • 1970-01-01
      • 2012-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-04
      • 1970-01-01
      相关资源
      最近更新 更多