简体   繁体   English

如何在图像中放置关闭图标:bootstrap 3 modal

[英]How to place close icon inside the image: bootstrap 3 modal

I am using bootstrap modal to create a thumbnail gallery that displays an attempt of full-size images when its thumbnail is clicked. 我正在使用引导模态来创建一个缩略图库,该缩略图库在单击其缩略图时会显示全尺寸图像的尝试。

I managed to make everything work fine and changed the css a bit but I don't find the way to make the closing "x" button be displayed inside the image, preferably in the top right side of it. 我设法使一切正常,并稍微更改了CSS,但是我没有找到使关闭的“ x”按钮显示图像内(最好在图像的右上角)的方法。

Here's my HTML: 这是我的HTML:

<div id="galeria" class="modal fade" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <div class="modal-body"></div>
      </div>
    </div>
  </div>
</div>

The script that makes the whole thing work: 使整个事情起作用的脚本:

<script type='text/javascript'>
$(document).ready(function() {
  $('.thumbnail').click(function(){
    $('.modal-body').empty();
    $("<button type='button' class='close' style='font-size:30px' data-dismiss='modal'>×</button>").appendTo('.modal-body');
    $($(this).parents('div').html()).appendTo('.modal-body');
    $('#galeria').modal({show:true});
  });
});
</script>

What should I do to achieve my goal? 我应该怎么做才能实现自己的目标? I am using Bootstrap 3. 我正在使用Bootstrap 3。

Hello, dabadaba! 你好,达巴达巴!

WORKING FIDDLE : http://jsfiddle.net/Ed2Q7/2/ 工作场所http : //jsfiddle.net/Ed2Q7/2/

You'll want to make sure the modal has position:relative; 您需要确保模式具有position:relative; and that your image and button have position:absolute; 并且您的图片和按钮的position:absolute; .

So here's an example: 所以这是一个例子:

.modal {
    position: relative;
}
.modal img { /* select the image tag inside the modal. */
    position: absolute;
    top:0;
    left:0;
    z-index:50; /* for good measure */
}
.modal .close { /* select the close button */
    position: absolute;
    top:0;
    right:0;
    z-index:51; /* place it over the img */
}

Foot note: If your image is just a background image inside a div, just set the div to position: relative; 脚注:如果您的图像只是div内的背景图像,只需将div设置为position: relative; and place the close button inside with the same position: absolute; top:0; right:0; 然后将关闭按钮放在同一position: absolute; top:0; right:0; position: absolute; top:0; right:0; style. 样式。

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

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