CSS - position button inside image

只谈情不闲聊 提交于 2019-11-30 14:21:14

You should give the div containing the image a position:relative and your button that is contained within that div a position:absolute. That will position the button relative to the container div.

If you don't have an specific reason to be using an img tag for this I would use a div structure like this:

<div id="my_image">
<button id="button_id" />
</div>

To get the button to position correctly you are going to want to set the div position to "relative" and the button position to "absolute". This means the absolute position of the button will be based on the top left of the wrapping div.

An example of this css would be:

#my_image { position: relative; }
#button_id { position: absolute; right: 5px; top: 5px; }

The above CSS will put your button in the top right with 5px of space between it and the corner of the div.

Take a look this example below: an image with previous and next button over it.

 <div class="thumbnail rec thmbnail-large">
    <img class="img-thumbnail img-thumbnail-large-0 img-responsive" src="http://daniel-ethiopia.rhcloud.com/nivo/2.jpg" data-holder-rendered="true"  width="100%" style="margin-left:0px;height:auto;">
    <input type ="button" class="classic_button_next btn btn-primary btn-large" id="next_button" value="Next >>"/>
    <input type ="button" class="classic_button_prev btn btn-primary btn-large" id="prev_button" value="Previous <<"/>            
 </div>

CSS===========================================

<style type="text/css">
.classic_button_next{ position: absolute; right: 5px; top: 5px; }
.classic_button_prev { position: absolute; right: 88px; top: 5px; }
<style>

JScript======================= Ask and i will be discussed how you work with the next and previous thing.despite that this is a working example.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!