michaelmcgurk michaelmcgurk - 4 months ago 127
CSS Question

Position button over image Bootstrap CSS

I'd like to position my button centrally vertically and horizontal over my image.

How do I do this with the code? Demo: https://jsfiddle.net/bdec5ezo/

Also, once it gets to tablet and mobile, can I push me button so it's on the left hand side and not centered?



/* Latest compiled and minified CSS included as External Resource*/

/* Optional theme */
@import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');

body {
margin: 10px;
}

img {
max-width:100%
}

.btn {
background: rgba(0,0,0,0);
border: 1px solid #ffca00;
border-radius: 0;
color: #ffca00;
display: block;
font-size: 18px;
margin: 0 auto;
padding: 10px 55px;
text-shadow: none;
transition: all .5s ease 0s;
}

.row {
position:relative
}

button {
position:absolute;
top:40%;
left:40%

}

<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<img src="https://placeholdit.imgix.net/~text?txtsize=141&txt=2073%C3%97563&w=2073&h=563">
<a href="http://www.google.com"><button class="btn btn-default btn-yellow" type="submit">Shop Now</button></a>
</div>
</div>




Answer

Try This FIDDLE

/* Latest compiled and minified CSS included as External Resource*/

/* Optional theme */
@import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');

body {
    margin: 10px;
}

img {
  max-width:100%
}

.btn {
    background: rgba(0,0,0,0);
    border: 1px solid #ffca00;
    border-radius: 0;
    color: #ffca00;
    display: block;
    font-size: 18px;
    margin: 0 auto;
    padding: 10px 55px;
    text-shadow: none;
    transition: all .5s ease 0s;
    -ms-transform: rotate(90deg); /* IE 9 */
    -webkit-transform: rotate(90deg); /* Chrome, Safari, Opera */
    transform: rotate(90deg);
}

.row {
  position:relative
}

button {
  position:absolute;
  top:40%;
  left:38%
  
}
@media (max-width:768px){
  button {left:0%}
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<div class="container">
      <div class="row">
          <img src="https://placeholdit.imgix.net/~text?txtsize=141&txt=2073%C3%97563&w=2073&h=563">
          <a href="http://www.google.com"><button class="btn btn-default btn-yellow" type="submit">Shop Now</button></a>
      </div>
</div>