html - 在图像上放置按钮 Bootstrap CSS

标签 html css twitter-bootstrap

我想将按钮垂直和水平放置在图片的中央。

如何使用代码执行此操作? 演示: https://jsfiddle.net/bdec5ezo/

此外,一旦它到达平板电脑和手机,我可以按下按钮使其位于左侧而不是居中吗?

/* 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>

最佳答案

试试这个 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>

关于html - 在图像上放置按钮 Bootstrap CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38686621/

相关文章:

javascript - JS 中可重用类的多个 $this 属性

html - Bootstrap CSS : body not containing all elements on page

javascript - 如何为小型设备手动启用 Bootstrap 响应菜单

jquery - 如何在 :after 范围内使用 JQuery CSS 从选择器动态更改颜色

html - 使div的背景与 body 背景合并

javascript - 使用 jQuery 动态更改元标记

html - css选择文件css样式不起作用

html - overflow-x 不适用于 td 中包含的内容

html - 裁剪背景图像

html - 全高背景图像,宽度居中