繁体   English   中英

Twitter Bootstrap Modal - 灰色背景但没有窗口

[英]Twitter Bootstrap Modal - Grey background but no window

我在Twitter Bootstrap和模态的非JS示例中遇到了一个奇怪的问题,所发生的是模态背景出现(灰色)但窗口没有。

我发现如果我从模态窗口div中删除“隐藏”类,它将加载但不正确。

小提琴在这里: http//jsfiddle.net/2VbUG/1/

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="John Moss - Stolen Bikes UK">
    <title>Title</title>

    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">

    <!-- Optional theme -->
    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css">

    <!-- Custom styles for this template -->
    <link href="assets/css/style.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="assets/js/html5shiv.js"></script>
      <script src="assets/js/respond.min.js"></script>
    <![endif]-->
</head>
<body>
    <div class="navbar navbar-inverse navbar-fixed-bottom">
      <div class="container">
        <div class="col-lg-12 sign">
              <a href="#myModal" role="button" class="btn btn-lg btn-danger" data-toggle="modal">Sign!</a>
        </div>
      </div>
    </div>
    <div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h3 id="myModalLabel">Sign This Petition!</h3>
        </div>
        <div class="modal-body">
            <p>Fields for the signatures here, take some from the facebook API</p>
        </div>
        <div class="modal-footer">
            <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
            <button class="btn btn-primary">Sign Now!</button>
        </div>
    </div>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="//code.jquery.com/jquery.js"></script>
    <!-- Bootstrap core JavaScript
    ================================================== -->
    <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
</body>
</html>

代码来自Bootstraps网站http://getbootstrap.com/2.3.2/javascript.html#modals上的本教程

您正在引用Bootstrap版本3 css但使用版本2示例代码。

尝试使用版本3示例代码。

我有一个类似的问题,并能够通过将模式移动到页面顶部来解决它。 这样做后,背景和模态窗口都出现了。 我花了大约4个小时的时间研究出来,所以我希望这有助于其他人!

问题是您正在加载bootstrap 3,但查看版本2.3.2的文档。 查看我制作的演示( 片段结果 ),如果加载当前版本,它可以正常工作。

我认为您使用的是Bootstrap 3.0 JavaScript和CSS资源,但使用的是Bootstrap 2.3.2 HTML。 我用Bootstrap 3.0 HTML标记更新了你的小提琴: http//jsfiddle.net/UWv9q/1/

<!-- Button trigger modal -->
<a data-toggle="modal" href="#myModal" class="btn btn-lg btn-danger">Sign!</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-hidden="true">&times;</button>
        <h4 class="modal-title">Sign this petition!</h4>
      </div>
      <div class="modal-body">
        <p>Fields for the signatures here, take some from the facebook API</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Sign now!</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

以上所有答案都让我误入歧途。

我的问题就像OP所说的那样,除了我的问题是我的草率CSS隐藏/移动模式关闭屏幕。

我点击了元素查看器中的节点并关闭了所有CSS规则,它按预期显示在屏幕中间。

我遇到了同样的问题,将模态窗口的z-index设置为固定它的页面上的最高值。

<style>
.myModalWindow{
    z-index: 10;//or higher, depends on z-index of other elements on your page
}
</style>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM