只需添加元素并使用
position:absolute
与
transform:rotate
把徽章盖在卡片上。
使用
text-center
用于文本居中的位置。
body {
padding:50px; /* this is just to get some space, unneccessary for the badge implementation itself */
}
.card {
position:relative;
}
.card .card-badge {
position:absolute;
top:-10px;
left:-30px;
padding:5px;
background:blue;
color:white;
transform:rotate(-20deg);
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="https://dummyimage.com/286x180" alt="Card image cap">
<div class="card-body text-center">
<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 class="card-badge">Strawberries</div>
</div>