【问题标题】:Bootsrap 4 modal is not working in sticky-top navbarBootstrap 4 模态在置顶导航栏中不起作用
【发布时间】:2019-04-18 07:35:38
【问题描述】:

我在置顶导航栏中使用了模式。但是模态不能正常工作。当我删除粘顶模态时,它正在工作。 在此处粘贴我的代码:

我在置顶导航栏中使用了模式。但是模态不能正常工作。当我删除粘顶模态时,它正在工作。 在此处粘贴我的代码:

<!DOCTYPE HTML>
    <html>
    <head>
    <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">


    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<title>Modal</title>

</head>
 <style>


 </style>
<body>

<div class="navbar sticky-top">


   <button type="button" class="btn btn-outline-light" data-toggle="modal" data-target="#exampleModalCenter">
    <img src="help.jpg">
    </button>


    <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
      <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
                  <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalCenterTitle">Customer Support</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                      <span aria-hidden="true">&times;</span>
                    </button>
                  </div>  
            </div>
        </div>
     </div>


</div>









 <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>


</body>
</html>

【问题讨论】:

  • 这个问题也不起作用。请在问题中添加问题的相关代码sn-p。不要指望任何人挖掘您网站的代码。此外,它使这个问题在没有代码的情况下对将来的参考毫无用处。
  • 抱歉我的错误@SuperDJ
  • 你认为这是一个家庭作业网站?提供一些代码,向我们展示您的尝试。你很幸运@CodeGator 回答了你的问题。但是等等,根本没有问题。
  • 对不起,先生。我试图提供代码,但当时有一些错误。我不熟悉这个网站。尝试学习如何提出问题以及如何添加代码。对不起我的错误@Tenzolinho

标签: html css bootstrap-4 navbar


【解决方案1】:

改变位置:固定;从 .modal-backdrop 到 position: unset; 就完成了……

.modal-backdrop {
  position:unset !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<html><head>
<!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

	
 
<title>Modal</title>
 
</head>
 
<body class="">
 
<div class="navbar sticky-top">
  
 
   <button type="button" class="btn btn-outline-light" data-toggle="modal" data-target="#exampleModalCenter">
	<img src="help.jpg">
	</button>


	<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" style="display: none;" aria-hidden="true">
	  <div class="modal-dialog modal-dialog-centered" role="document">
			<div class="modal-content">
				  <div class="modal-header">
					<h5 class="modal-title" id="exampleModalCenterTitle">Customer Support</h5>
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					  <span aria-hidden="true">×</span>
					</button>
				  </div>  
			</div>
		</div>
	 </div>
	 
	 
</div>





 
 
 
 
 <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
 
 

</body></html>

【讨论】:

  • 谢谢 :) @CodeGator
【解决方案2】:

将模型代码移出导航栏。 模态将与背景一起正常工作。

<!DOCTYPE HTML>
    <html>
    <head>
    <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">


    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<title>Modal</title>

</head>
 <style>


 </style>
<body>

<div class="navbar sticky-top">


   <button type="button" class="btn btn-outline-light" data-toggle="modal" data-target="#exampleModalCenter">
    <img src="help.jpg">
    </button>
</div>


<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
          <div class="modal-content">
                <div class="modal-header">
                  <h5 class="modal-title" id="exampleModalCenterTitle">Customer Support</h5>
                  <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                  </button>
                </div>  
          </div>
      </div>
   </div>

 <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>


</body>
</html>

【讨论】:

    猜你喜欢
    • 2019-01-26
    • 2018-03-22
    • 2018-09-03
    • 1970-01-01
    • 2016-10-23
    • 2023-04-08
    • 2020-07-17
    • 2018-09-07
    • 2021-10-15
    相关资源
    最近更新 更多