簡體   English   中英

將bootstrap模態的關閉圖標放在圖像上

[英]Place bootstrap modal's close icon over the image

我在頁面加載中使用bootstrap模式我想在圖像上放置一個關閉圖標。目前我使用一個按鈕來關閉模態。

<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-body">
      <div class="hfc">
      <img class="mySlides w3-animate-fading" src="assets/frontend/img/use/1.jpg"/>
      </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

<script type="text/javascript">
         $(window).load(function(){        
       $('#myModal').modal('show');
        }); 
    </script>

這樣你就可以設置圖像了

.hfc{
  position:relative;
}
.hfc img{
  width:100%;
}
.close{
  position:absolute;
  top:5px;
  right:5px;
}

 jQuery(document).ready(function(e) { jQuery('#mymodal').trigger('click'); }); 
 .hfc{ position:relative; } .hfc img{ width:100%; } .close{ position:absolute; top:5px; right:5px; } 
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> <!-- Button trigger modal --> <button type="button" id="mymodal" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal"> Launch demo modal </button> <!-- Modal --> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-body"> <div class="hfc"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> <img class="mySlides w3-animate-fading" src="https://www.google.co.in/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"/> </div> </div> </div> </div> </div> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM