I have an image in which I need to put a button over, the problem is that I don't know how to place the button and automatically re-size and position it when making the browser smaller, right now I have the button in place, but when I re-size the browser to get smaller the button moves, I tried using percentages in the css buy doesn't work, what can I do?
<div id="discover" class="container-fluid">
<div class="row-fluid">
<div class="col-lg-12 col-sm-12 col-xs-12 col-md-12 withimg">
<img id="discoveryour" src="img/x.png" class="img-responsive">
</div>
</div>
<div class="row-fluid">
<div id="bttnimg" class="col-lg-12 col-sm-12 col-xs-12 col-md-12">
<form id="start" method="post" action="x.php">
<button class="btn-primary">text</button>
</form>
</div>
</div>
</div>
Css:
.withimg {
width: 100%;
overflow:hidden;
padding: 0px;
margin: 0px;
}
#discover{
position: relative;
}
#bttnimg{
float: left;
position: absolute;
left: 62%;
top: 25%;
max-width: 750px;
}
Ah, the good old "how to overlay stuff on top of a responsive image -- responsively" question.
A little tricky, but not too bad. The tricky bit is how to make the stuff's vertical position responsive when the image size changes.
Fear not, here's one simple way to do this:
HTML:
CSS:
The
img-overlay:before
pseudo-class handles the vertical positioning job by pushing theimg-overlay
div down from the top of the image. In this example, the top of the button will always be 50% down the image (change theheight: 50%
attribute if you want the button higher or lower).jsfiddle
To make the button size responsive to window width, you can create a new class for your button. Let's call it
btn-responsive
(this replacesbtn-md
in the example above). Then use@media
queries to adjust thebtn-responsive
attributes for different window widths. Something like this:and so forth for other screen widths.
I have to ask if there's a possibility to replace form tag into another DIV? Then you can just use
position: absolute
for button. I created fiddle to show how https://jsfiddle.net/1x1pjwk7/