Bootstrap 我正试图定位图像卡,以覆盖卡的顶部边界使用“引导”,需要帮助,或者我可以做它只与CSS?

z6psavjg  于 2022-12-07  发布在  Bootstrap
关注(0)|答案(2)|浏览(199)

我想使用Bootstrap?而不使用css来定位图像卡以覆盖卡的顶部边框。
我试过使用CSS:

style="margin: -50px 70px;"

但我想用bootstrap来实现

bz4sfanl

bz4sfanl1#

这可以通过以下类position-absolute top-0 start-50 translate-middle来完成,它将从顶部开始,从左到右居中定位元素0的中间。https://getbootstrap.com/docs/5.2/utilities/position/#center-elements
以下是一个示例:

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">

<div class="container">
  <div class="row">
    <div class="col-12 col-sm-6 col-md-4 col-lg-3 mt-5">
      <div class="card mt-5 pt-5">
        <img src="https://www.fillmurray.com/200/200" class="rounded-circle w-50 position-absolute top-0 start-50 translate-middle" alt="">
        <div class="card-body text-center pt-5">
          <h5 class="card-title">Card title</h5>
          <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
          <p>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
          </p>
        </div>
      </div>
    </div>
    <div class="col-12 col-sm-6 col-md-4 col-lg-3 mt-5">
      <div class="card mt-5 pt-5">
        <img src="https://www.fillmurray.com/199/200" class="rounded-circle w-50 position-absolute top-0 start-50 translate-middle" alt="">
        <div class="card-body text-center pt-5">

          <h5 class="card-title">Card title</h5>
          <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
          <p>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
          </p>
        </div>
      </div>
    </div>
    <div class="col-12 col-sm-6 col-md-4 col-lg-3 mt-5">
      <div class="card mt-5 pt-5">
        <img src="https://www.fillmurray.com/200/198" class="rounded-circle w-50 position-absolute top-0 start-50 translate-middle" alt="">
        <div class="card-body text-center pt-5">

          <h5 class="card-title">Card title</h5>
          <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
          <p>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
          </p>
        </div>
      </div>
    </div>
    <div class="col-12 col-sm-6 col-md-4 col-lg-3 mt-5">
      <div class="card mt-5 pt-5">
        <img src="https://www.fillmurray.com/200/199" class="rounded-circle w-50 position-absolute top-0 start-50 translate-middle" alt="">
        <div class="card-body text-center pt-5">

          <h5 class="card-title">Card title</h5>
          <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
          <p>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
          </p>
        </div>
      </div>
    </div>
  </div>
</div>

请注意,.col.card.card-body上的margin和padding类是防止图像与其他元素重叠或脱离画布所必需的。

6tqwzwtp

6tqwzwtp2#

您问题不清楚,而且您也没有提供任何代码,所以我认为您可以这样解决这个问题:

<div class="row">
   <div class="col-md-6 col-xl-3">
     <div class="border border-dark text-center">
          <img
            width="90"
            height="90"
            style="border-radius: 100%; margin-top: -45px"
            src="https://randomuser.me/api/portraits/women/65.jpg"
            alt=""
          />
          <h3>Name Here</h3>
          <p>
            Lorem ipsum dolor sit amet consectetur adipisicing elit.
            Necessitatibus pariatur nisi veniam dolorem architecto, 
            voluptatibus maxime eaque accusantium illum magni.
          </p>
     </div>
   </div>
 </div>

忽略rowcol-md-6 col-xl-3类。这些类是用来给予一个像你的图像一样的形状的。简单地说,你可以用margin-top css来解决你的问题。

相关问题