admin管理员组文章数量:1427984
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.
Here's my 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.
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.
Here's my 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.
Share Improve this question asked Jan 14, 2014 at 19:31 dabadabadabadaba 9,54221 gold badges95 silver badges170 bronze badges 3- 1 What CSS have you tried? Provide a JSFiddle if possible – Shai Commented Jan 14, 2014 at 19:34
- Bootstrap modal css, I didnt' change it. Well, I did, but it doesn't interfere with with what I am asking. – dabadaba Commented Jan 14, 2014 at 19:40
- you may want to try using negative margins in your CSS file. Either that or do not specify the close as 'x' but instead use a div or span with associate background image. You will then have much more control over size, position and display. – Philip Bevan Commented Jan 14, 2014 at 20:59
1 Answer
Reset to default 2Hello, dabadaba!
WORKING FIDDLE: http://jsfiddle/Ed2Q7/2/
You'll want to make sure the modal has position:relative;
and that your image and button have 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;
and place the close button inside with the same position: absolute; top:0; right:0;
style.
本文标签: javascriptHow to place close icon inside the image bootstrap 3 modalStack Overflow
版权声明:本文标题:javascript - How to place close icon inside the image: bootstrap 3 modal - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745514538a2661466.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论