【问题标题】:Overlay horizontal text over bootstrap5 grid在 bootstrap5 网格上覆盖水平文本
【发布时间】:2022-02-14 18:28:16
【问题描述】:

在我的网站上工作,我认为自己是 Boostrap5 并且对目前的结果非常满意,但我希望 名称在悬停在左下角的图像上垂直显示,但我不确定我的代码哪里出错了。文本放置在非常低的位置并位于网格列的边缘。

我确定我的 position: 属性或其他东西有问题。

.theteam img {
  cursor: pointer;
}

.theteam img:hover {
  opacity: 0.8;
}

.project {
  position: relative;
  overflow: hidden;
}

.project .overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 30px;
  display: flex;
  align-items: flex-end;
  transition: all 0.4s ease;
  opacity: 0;
}

.project img {
  transition: all 0.4s ease;
}

.project:hover .overlay {
  opacity: 1;
}

.project:hover img {
  transform: scale(1.1);
}

.text-vertical {
  transform-origin: 0 0;
  transform: rotate(90deg);
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

<section id="about" class="about bg-dark p-5">
  <div class="container text-center mt-5">
    <h4 class="text-light text-capitalize mb-0">The rocking team</h4>
    <img src="https://poyo-pat-333.netlify.app/images/underline.png" alt="______"></span>
  </div>

  <div class="container theteam mt-5">
    <div class="row g-4 text-center">
      <div class="col-md-3 col-sm-6 project inline-block overlay">
        <img src="https://poyo-pat-333.netlify.app/images/poyo_moya.jpg" alt="team">
        <div class="text-center">
          <h6 class="text-white text-vertical position-absolute">Poyo Moya</h6>
        </div>
      </div>
      <div class="col-md-3 col-sm-6 project">
        <img src="https://poyo-pat-333.netlify.app/images/regi-villardell.jpg" alt="team">
        <div>
          <div>
            <h6 class="text-white text-vertical">Regi Vilardell</h6>
          </div>
        </div>
      </div>
      <div class="col-md-3 col-sm-6 project">
        <img src="https://poyo-pat-333.netlify.app/images/oriol_fontanals.jpg" alt="team">
        <div>
          <div>
            <h6 class="text-white text-vertical">Oriol Fontanals</h6>
          </div>
        </div>
      </div>
      <div class="col-md-3 col-sm-6 project">
        <img src="https://poyo-pat-333.netlify.app/images/Patrick_obrien.jpg" alt="team">
        <div class="">
          <div>
            <h6 class="text-white text-vertical">Patrick O'Brien</h6>
          </div>
        </div>
      </div>
    </div>
  </div>

</section>

谢谢。

【问题讨论】:

  • codepen 链接已失效。

标签: css css-grid bootstrap-5


【解决方案1】:

我已经更新了你的.text-vertical,看看:

UPD:我制作了 .text-top 类来将文本与图像顶部对齐。

.theteam img {
  cursor: pointer;
}

.theteam img:hover {
  opacity: 0.8;
}

.project {
  position: relative;
  overflow: hidden;
}

.project .overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 30px;
  display: flex;
  align-items: flex-end;
  transition: all 0.4s ease;
  opacity: 0;
}

.project img {
  transition: all 0.4s ease;
}

.project:hover .overlay {
  opacity: 1;
}

.project:hover img {
  transform: scale(1.1);
}

.text-vertical {
  transform-origin: 0 0;
  transform: rotate(270deg);
  /* here */
  width: fit-content;
  /* this line is important */
}

/* top align for vertical text */
.text-vertical.text-top {
  position: absolute;
  top: 0;
  left: 0;
  transform: rotate(-90deg) translate3D(-100%, 0, 0);
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

<section id="about" class="about bg-dark p-5">
  <div class="container text-center mt-5">
    <h4 class="text-light text-capitalize mb-0">The rocking team</h4>
    <img src="https://poyo-pat-333.netlify.app/images/underline.png" alt="______">
  </div>

  <div class="container theteam mt-5">
    <div class="row g-4 text-center">
      <div class="col-md-3 col-sm-6 project inline-block overlay">
        <img src="https://poyo-pat-333.netlify.app/images/poyo_moya.jpg" alt="team">
        <div class="text-center">
          <h6 class="text-white text-vertical position-absolute">Poyo Moya</h6>
        </div>
      </div>
      <div class="col-md-3 col-sm-6 project">
        <img src="https://poyo-pat-333.netlify.app/images/regi-villardell.jpg" alt="team">
        <div>
          <div>
            <h6 class="text-white text-vertical">Regi Vilardell</h6>
          </div>
        </div>
      </div>
      <div class="col-md-3 col-sm-6 project">
        <img src="https://poyo-pat-333.netlify.app/images/oriol_fontanals.jpg" alt="team">
        <div>
          <div>
            <h6 class="text-white text-vertical">Oriol Fontanals</h6>
          </div>
        </div>
      </div>
      <div class="col-md-3 col-sm-6 project">
        <img src="https://poyo-pat-333.netlify.app/images/Patrick_obrien.jpg" alt="team">
        <div class="">
          <div>
            <h6 class="text-white text-vertical">Patrick O'Brien</h6>
          </div>
        </div>
      </div>
    </div>
  </div>


  <div class="container theteam mt-5">
    <div class="row g-4 text-center">
      <div class="col-md-3 col-sm-6 project inline-block overlay">
        <img src="https://poyo-pat-333.netlify.app/images/poyo_moya.jpg" alt="team">
        <div class="text-center">
          <h6 class="text-white text-vertical text-top">Poyo Moya</h6>
        </div>
      </div>
      <div class="col-md-3 col-sm-6 project">
        <img src="https://poyo-pat-333.netlify.app/images/regi-villardell.jpg" alt="team">
        <div>
          <div>
            <h6 class="text-white text-vertical text-top">Regi Vilardell</h6>
          </div>
        </div>
      </div>
      <div class="col-md-3 col-sm-6 project">
        <img src="https://poyo-pat-333.netlify.app/images/oriol_fontanals.jpg" alt="team">
        <div>
          <div>
            <h6 class="text-white text-vertical text-top">Oriol Fontanals</h6>
          </div>
        </div>
      </div>
      <div class="col-md-3 col-sm-6 project">
        <img src="https://poyo-pat-333.netlify.app/images/Patrick_obrien.jpg" alt="team">
        <div class="">
          <div>
            <h6 class="text-white text-vertical text-top">Patrick O'Brien</h6>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>

【讨论】:

  • 太棒了。这让我离我的目标更近了!非常感谢!我现在唯一不知道如何解决的问题是无论列有多宽,文本始终位于图像顶部。目前这取决于视口宽度。
  • @Boxhamster 我已经创建了 .text-top 类来将文本与图像顶部对齐。
  • @Boxhamster 如果这回答了你的问题,你能接受这个答案吗?
猜你喜欢
  • 1970-01-01
  • 2017-05-26
  • 1970-01-01
  • 1970-01-01
  • 2013-07-10
  • 2021-08-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多