【问题标题】:twitter bootstrap 3 and bootswatch flatly template - modal not working anylongertwitter bootstrap 3 和 bootswatch flatly 模板 - 模态不再工作
【发布时间】:2015-05-22 13:59:44
【问题描述】:

在我从 bootswatch (https://bootswatch.com/flatly/) 安装 flatly 模板后,twbs 的正常模式窗口不再工作。

<a data-toggle="modal" href="#" data-target="#myModal">CLICK!</a>
.
.
        <!-- Modal -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</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>

    </body>
</html>

在我将主题添加到我的应用程序之前,它可以完美运行。

这意味着模态窗口出现了,但它不是活动的。 模态窗口出现在灰色背景后面。模态窗口没有焦点。我也关不了 但为什么呢?

【问题讨论】:

    标签: css twitter-bootstrap modal-dialog bootstrap-modal bootswatch


    【解决方案1】:

    试试这样:

    <div class="modal">
        <div class="modal-dialog">
            <div class="modal-content">
                 <div class="modal-header">
                      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                       <h4 class="modal-title">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>
    

    【讨论】:

      【解决方案2】:

      我也遇到过同样的问题。 但后来我注意到我使用的是 Bootstrap v3.3.2,而 Flatly css 文件中的版本是 v3.3.4

      所以我将 bootstrap.js 文件更新到了最新版本(目前是 3.3.4)并且它工作正常。

      希望这会有所帮助。

      【讨论】:

        【解决方案3】:

        Bootstrap 为其变量文件中的以下项目设置 z-index:

        @zindex-navbar:            1000;
        @zindex-dropdown:          1000;
        @zindex-popover:           1060;
        @zindex-tooltip:           1070;
        @zindex-navbar-fixed:      1030;
        @zindex-modal-background:  1040;
        @zindex-modal:             1050;
        

        bootswatch 变量文件中项目的 z-index 设置如下:

        @zindex-navbar:            1000;
        @zindex-dropdown:          1000;
        @zindex-popover:           1060;
        @zindex-tooltip:           1070;
        @zindex-navbar-fixed:      1030;
        @zindex-modal:             1040;
        

        如您所见,bootswatch 模态设置在与 bootstrap 模态背景相同的索引上。这种冲突正在引起问题。将 bootswatch 模式的 z-index 设置为 1050 将解决您的问题,或者在您网站的样式表中添加对 .modal z-index 的覆盖也会有所帮助。

        .modal {z-index: 1050;}
        

        【讨论】:

        • 我必须添加 .modal-dialog {z-index: 1050;} 才能让它为我工作,但是这两个规则一起为我解决了这个问题。我的 Bootstrap 模式现在可以正常工作了。谢谢,史蒂夫。
        【解决方案4】:

        感谢史蒂夫!对我有帮助的确切覆盖(与 Flatly 有同样的问题):

        .modal-dialog {
          z-index: 1050;}
        

        【讨论】:

        • 请不要添加“谢谢”作为答案。一旦你有足够的reputation,你就可以vote up questions and answers你觉得有帮助。
        • 欢迎来到 StackOverflow Alex。删除对Steve's answer 的归属(并感谢),您只是想报告这对您有用,这不是@dbugger 对他的评论的意思。他想说的是StackOverflow“不赞成”重复(部分)报告有效的答案并感谢发布该信息的用户(实际上我们鼓励将其标记为“不是答案”)。相反,我们投票赞成(当需要或有帮助时,我们会对该有帮助的答案发表评论)。
        猜你喜欢
        • 2017-02-21
        • 1970-01-01
        • 2013-08-29
        • 2016-05-05
        • 2012-04-14
        • 1970-01-01
        • 2013-01-30
        • 1970-01-01
        • 2012-08-19
        相关资源
        最近更新 更多