使用相对位置时如何获得引导卡下方的内容

时间:2018-10-26 18:35:48

标签: html css bootstrap-4

我正在使用图像创建引导卡。使用position: absolutetop将卡身向上移动到图像上。

当我在卡片下方添加一个新的div时,该div将被推到图像上。我需要将内容留在卡身下方。

我希望这是有道理的,但是要清除任何混淆,请查看jsfiddle。如果您需要更多信息,请告诉我。

这是两难的形象: enter image description here

1 个答案:

答案 0 :(得分:2)

只需从.card-body规则中删除position: absolute; top: 320px; left: 76px;样式,然后添加margin-top:-50px; margin-left: 50px;

.row {
  background: #f8f9fa;
  margin-top: 20px;
}

.col {
  border: solid 1px #6c757d;
  padding: 10px;
}
.card {
    border: none;
}
.card-body {
  width: 80%;
   border: 1px solid rgba(0,0,0,.125);
    border-radius: .25rem;
    background: #fff;
    /*position: absolute;
    top: 320px;
    left: 76px;*/
    margin-top:-50px;
    margin-left: 50px;
}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>

<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<!-- 
  Bootstrap docs: https://getbootstrap.com/docs
-->

<div class="container">

<div class="card" style="width: 100%;">
  <img class="card-img-top" src="http://getbootstrap.com/docs/4.1/assets/brand/bootstrap-social.png" alt="Card image cap">
  <div class="card-body">
    <h5 class="card-title">Card title</h5>
    <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
    <a href="#" class="btn btn-primary">Go somewhere</a>
  </div>
</div>
</div>
<div>
I need this text to be underneath the card.I tried using margin-bottom for the card, but the problem with this is the content of the card body changed, therefore the height changes which is what i want.
</div>

您也可以here对其进行测试。