【问题标题】:Put heading on top of Responsive image without Flexbox在没有 Flexbox 的情况下将标题放在响应式图像的顶部
【发布时间】:2017-03-08 22:21:47
【问题描述】:

我想在图像顶部放置一个标题,垂直和水平居中对齐。我通过 Flexbox 实现了它。但是,有些浏览器不支持 Flexbox。没有flexbox有什么办法吗?

注意:图片必须是响应式的。所以我不能为 div 使用背景图片

<div class="col-md-3 col-6 category" @click="openPopup('cement')">
  <img src="https://www.quotzap.com/static/images/categories/cement.jpg" width="100%" />
  <h2>Cement</h2>
</div>

.category{
  cursor: pointer;
  transition: all .2s ease;
  justify-content: center;
  display: -webkit-flex;
  display: flex;
  align-items: center;
}
.category h2{
  max-width: 100px;
  text-align: center;
  position: absolute;
  color: #ffffff;
  line-height: 1.5;
}
.category img{
  border-radius: 5px;
  box-shadow: 0px 2px 10px 0px rgba(143,143,143,0.68);
  position: relative;
  -webkit-filter: brightness(70%);
  transition: all .2s ease;
}

【问题讨论】:

    标签: html css twitter-bootstrap flexbox


    【解决方案1】:

    如果您不想使用弹性框,请尝试将您的 CSS 更改为此...

    .category{
      cursor: pointer;
      transition: all .2s ease;
      justify-content: center;
      position: relative;
      align-items: center;
      z-index: 0;
    }
    .category h2{
      max-width: 100px;
      text-align: center;
      top:50%;
      left:50%;
      transform:translate(-50%, -50%);
      width:50%;
      position: absolute;
      color: #ffffff;
      line-height: 1.5;
      z-index:2;
    }
    .category img{
      z-index: 1;
      border-radius: 5px;
      box-shadow: 0px 2px 10px 0px rgba(143,143,143,0.68);
      position: relative;
      -webkit-filter: brightness(70%);
      transition: all .2s ease;
    }
    

    【讨论】:

    • 不用担心...很高兴它解决了您的问题。
    猜你喜欢
    • 2021-02-15
    • 1970-01-01
    • 2018-07-29
    • 1970-01-01
    • 1970-01-01
    • 2021-10-27
    • 1970-01-01
    • 2022-11-18
    • 1970-01-01
    相关资源
    最近更新 更多