【问题标题】:Bootsrap Modal does not scroll with the default browser page scroll barBootstrap Modal 不使用默认浏览器页面滚动条滚动
【发布时间】:2016-03-11 14:24:26
【问题描述】:

我在 php/codeIgniter 工作。但是我的问题与引导模式有关。
我编写的 Modal 的 HTML 如下:

<li><a href="#contactmodel" data-toggle="modal">Contact us</a>
    <div id="contactmodel" class="modal fade cmodal" role="dialog">
        <div class="modal-dialog modal-sm" role="document">                             
            <!-- Modal content-->
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title cus-modal-title">Contact Us | <span class="cus-modal-stitle">have your say...</span></h4>
                        </div>
                        <div class="modal-body">
                           <div class="col-md-10 col-md-offset-1 cus-model-margin">
                 <?php
                    $attributes = array('name' => 'contactform',
                    'target' => '_self',
                    'id' => 'contact', 'class' => 'htmlform' 
                     );
                     echo form_open('contactus', $attributes);
                     ?>                 
    <div class="form-group">
    <input type="text" class="form-control inputstyle-text" name="nick" id="nick" placeholder="Write your nick name ..." ng-model="nick" type="text" required pattern="^[A-Za-z]{5,15}$" title="Only alphabets allowed. Min. 2 & Max. 15" style="text-transform: lowercase">  <span class="glyphicon glyphicon-user" style="color: red"></span></input>
    </div>
    <div class="form-group">
    <input type="email" class="form-control inputstyle-text" name="email" id="email" placeholder="Write your email ..." ng-model="email" required type="email"   style="text-transform: lowercase">  <span class="glyphicon glyphicon-envelope" style="color: red"></span></input>
    </div>
    <div class="form-group">
    <textarea class="form-control text-style" rows="5" name="msg" id="msg" placeholder="Anything to say ..." ng-model="text" type="msg" required pattern="^[A-Za-z]{100,300}$" title="Only alphabets allowed. Max. 300" style="text-transform: lowercase"> </textarea>  <span class="glyphicon glyphicon-font" style="color: red"></span>
    </div>
    <div class="form-group">
    <button type="submit" name="submit" class="btn btn-primary">Send  <span class="glyphicon glyphicon-envelope" style="color: black"></span></button>
    </div>
            <?php echo form_close(); ?>             
                </div>  
                                        </div>
                                    </div>                          
                                </div>
                        </div>                          
                    </li>  

我正在使用 Bootstrap,但是我为 Modal 添加了一些自定义 css,仅此而已,如下所示:

.cus-modal-title{

     color: black;
     text-align: left !important;

 }
 .cus-modal-stitle{

     font-size: 10px;   

  }
  .cus-model-margin{

      margin-left: 0.333333% !important;
   }
   .modal.fade.in {

      top: 40% !important;
    }
    .cmodal{

      z-index: 1051 !important;

     }
     a:focus {

        outline: thin dotted #333;
        outline: 0px auto -webkit-focus-ring-color !important; 
        outline-offset: -2px;
      }
      .cus-model-body{

        background: url('../images/content.png');

       }

我已通过 contact-us 链接将模态框放在 footer 中。
现在的问题是模态框不随网络浏览器页面的默认滚动条。我使用的是 google-chrome。
任何形式的帮助将不胜感激。

【问题讨论】:

  • 这是因为页面上有multiple modals吗?
  • 页面上有模态框,但是它们与 MVC 中的视图不同。即使在同一页面上加载的不同视图中,模态也会产生影响吗?
  • 不,他们不会:)。我认为链接的帖子可能与您的问题有关,因为您不会期望这样的事情。
  • 欢迎优秀的cmets。我发现我使用的是自定义 bootstrap.css 文件。当我切换到官方引导程序时,一切都恢复正常了。

标签: javascript php html css twitter-bootstrap


【解决方案1】:

当我下载官方的引导 css 并替换为旧的,因为它已经被修改后,问题得到了解决。

【讨论】:

    【解决方案2】:

    这是因为位置属性应用于“.modal-dailog”类。

    如果您希望模态框随浏览器滚动条滚动,则必须将“.modal-dailog”类的位置设置为固定。我认为,默认情况下,它是绝对的并隐藏浏览器的滚动条,这样用户将永远无法滚动窗口,而模式将始终显示在屏幕上。

    谢谢

    【讨论】:

    • 实际上,每当打开一个modal时,一个modal-open就会添加到html的主体中。现在在新的引导 css modal-open 中默认设置为隐藏。这意味着当模式打开时,页面的滚动条由于隐藏属性而被删除。如果将其设置为滚动,则模式可以像往常一样随页面滚动。
    • 这意味着,如果模态对话框随页面滚动,则其位置已固定。不错:-)
    • :-)。是的,我们应该将其更改为绝对。固定可能不起作用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-31
    • 2020-03-07
    • 2010-09-06
    • 1970-01-01
    • 2019-03-10
    • 2015-11-10
    相关资源
    最近更新 更多