【问题标题】:Transparent overlay on responsive square grids响应式方形网格上的透明覆盖
【发布时间】:2018-01-14 03:36:06
【问题描述】:

我正在尝试制作响应式方形图像网格,每个网格由 9 个图像组成。

我只是使用简单的引导网格布局来制作网格 -

div class="col-md-4">
    <img class="home_images" src="#image*" style="height:25%; width:27%">
    <!--Nine more images like this-->
</div>

我需要在每个方形网格的顶部(绝对定位)添加一个覆盖灰色低不透明度正方形,以便在每个网格的中心添加 h2 文本。由于网格没有特定的高度,我该如何继续?

【问题讨论】:

  • 关于 SO 上图像叠加的问题有 数百个。尝试先进行搜索。
  • 叠加不是我的问题,我的问题是获取叠加 div 的高度。当每个 col-md-4 都没有指定高度时,如何叠加?我在搜索中找不到类似的响应式 div 问题。
  • 能否提供你的html css和js代码

标签: html css twitter-bootstrap layout twitter-bootstrap-3


【解决方案1】:

你的意思是这样的?

<!DOCTYPE HTML>

<html>

<head>
  <style>
    body {
      height: 100%;
      display: flex;
      justify-content: center;
    }
    
    .grid {
      width: 80%;
      height: 100%;
      border: 1px solid red;
      position: relative;
    }
    
    .row {
      width: 100%;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
    }
    
    .item {
      width: 30%;
      height: 100px;
      border: 1px solid blue;
    }
    
    .grid:after {
      content: "Heading Two Title"; /*allow to show up*/
      width: 100%;
      height: 100%; /*cover grid area*/
      position: absolute;
      top: 0;
      left: 0; /*make it stay on the grid*/
      background-color: #a0a0a0; /*instead of opacity choose a light gray color*/
      z-index: -1; /*place behind so as not to cover the grid elements*/
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 3em; /*make as big as needed*/
    }
  </style>
</head>

<body>
  <div class="grid">
    <div class="row">
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
    </div>

    <div class="row">
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
    </div>

    <div class="row">
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
    </div>
  </div><!-- /grid -->
</body>

</html>

【讨论】:

  • 这不是我想要的,但它确实帮助我朝着正确的方向前进。感谢您的回答
猜你喜欢
  • 2016-09-03
  • 2015-01-21
  • 2017-09-22
  • 2020-06-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-20
  • 2013-01-27
相关资源
最近更新 更多