相对/绝对排名

时间:2019-08-02 20:00:23

标签: html css

我想做的是在每个框的蓝色标题之后获得红色文本。

似乎我将不得不添加另一个div?我已经添加并修改了.card-indus img的位置,但是结果永远不是我想要的。

您知道为什么即使我将position:relative;应用于.industries .container-industries .card-indus img也不起作用吗?你有什么建议吗?

here

.industries .container-industries .card-indus {
  position: relative;
  border: red solid 1px;
  color: white;
  max-height: 300px;
  overflow: hidden;
  height: 100%;
}

.industries .container-industries .card-indus img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.5;
}

.industries .container-industries .card-indus .text-image {
  position: absolute;
  color: red;
  left: 0;
  top: 0;
}

.industries .container-industries .card-header {
  height: 4rem;
  display: flex;
  align-items: center;
  background: rgba(82, 134, 236, 0.6);
}

.industries .container-industries .card-header p {
  margin-left: 1rem;
}
<div class="industries">
  <div class="industries-icons">
    <h2> Our Industries</h2>
    <span class="border-1"></span>
    <div class="container-industries">
      <div class="card-indus">
        <div class="card-header">
          <p>Banking</p>
        </div>
        <div class="card-content">
          <img src="../images/services/finance.jpg">
          <p class="text-image">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quia voluptatibus numquam eveniet doloremque dignissimos veniam.</p>
        </div>
      </div>

      <div class="card-indus">
        <div class="card-header">
          <p>Admin</p>
        </div>
        <div class="card-content">
          <img src="../images/services/admin.jpg">
          <p class="text-image">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quia voluptatibus numquam eveniet doloremque dignissimos veniam.</p>
        </div>
      </div>

      <div class="card-indus">
        <div class="card-header">
          <p>Law</p>
        </div>
        <div class="card-content">
          <img src="../images/services/law.jpg">
          <p class="text-image">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quia voluptatibus numquam eveniet doloremque dignissimos veniam.</p>
        </div>
      </div>

      <div class="card-indus">
        <div class="card-header">
          <p>Retail</p>
        </div>
        <div class="card-content">
          <img src="../images/services/retail.jpg">
          <p class="text-image">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quia voluptatibus numquam eveniet doloremque dignissimos veniam.</p>
        </div>
      </div>
      <div class="card-indus">
        <div class="card-header">
          <p>Telecom</p>
        </div>
        <div class="card-content">
          <img src="../images/services/telecom.jpg">
          <p class="text-image">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quia voluptatibus numquam eveniet doloremque dignissimos veniam.</p>
        </div>
      </div>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

您将必须做两件事:

1-将text-image格移到img格之前。

2-如上所述,从position: absolute;中删除img

  .industries .container-industries .card-indus {
      position: relative;
      border: red solid 1px;
      color: white;
      max-height: 300px;
      overflow: hidden;
      height: 100%;
    }

    .industries .container-industries .card-indus img {
      display: block;
      width: 100%;
      height: 100%;
      object-fit: cover;
      opacity: 0.5;
    }

    .industries .container-industries .card-indus .text-image {
      color: red;
      left: 0;
      top: 0;
    }

    .industries .container-industries .card-header {
      height: 4rem;
      display: flex;
      align-items: center;
      background: rgba(82, 134, 236, 0.6);
    }

    .industries .container-industries .card-header p {
      margin-left: 1rem;
    }
  
 <div class="industries">
      <div class="industries-icons">
        <h2>Our Industries</h2>
        <span class="border-1"></span>
        <div class="container-industries">
          <div class="card-indus">
            <div class="card-header">
              <p>Banking</p>
            </div>
            <div class="card-content">
              <p class="text-image">
                Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quia
                voluptatibus numquam eveniet doloremque dignissimos veniam.
              </p>
              <img src="../images/services/finance.jpg" />
            </div>
          </div>

          <div class="card-indus">
            <div class="card-header">
              <p>Admin</p>
            </div>
            <div class="card-content">
              <p class="text-image">
                Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quia
                voluptatibus numquam eveniet doloremque dignissimos veniam.
              </p>
              <img src="../images/services/admin.jpg" />
            </div>
          </div>

          <div class="card-indus">
            <div class="card-header">
              <p>Law</p>
            </div>
            <div class="card-content">
              <p class="text-image">
                Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quia
                voluptatibus numquam eveniet doloremque dignissimos veniam.
              </p>
              <img src="../images/services/law.jpg" />
            </div>
          </div>

          <div class="card-indus">
            <div class="card-header">
              <p>Retail</p>
            </div>
            <div class="card-content">
              <p class="text-image">
                Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quia
                voluptatibus numquam eveniet doloremque dignissimos veniam.
              </p>
              <img src="../images/services/retail.jpg" />
            </div>
          </div>
          <div class="card-indus">
            <div class="card-header">
              <p>Telecom</p>
            </div>
            <div class="card-content">
                <p class="text-image">
                    Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quia
                    voluptatibus numquam eveniet doloremque dignissimos veniam.
                  </p>
              <img src="../images/services/telecom.jpg" />
            </div>
          </div>
        </div>
      </div>
    </div>