I try to put Title over the image, I want My card-title over my image not sure do I need CSS?
here is my HTML
<div class="card card-blog">
<div class="card">
<a href="#pablo">
<img class="img" src="assets/img/backgound.jpg">
</a>
</div>
<div class="card-body text-center">
<h4 class="card-title">
TEXT OVER IMAGE
</h4>
<div class="card-description">
<div class="table-responsive">
</div>
</div>
<div class="card-footer">
<a href="#pablo" class="btn btn-danger btn-round">View Article</a>
</div>
</div>
</div>
</div>
Output : Can I move card-title over image ?
Bootstrap 4 doesn't come with any native tools to achieve this within the card
component, but with a little additional CSS you can make it work:
.card-img-caption {
border-top-left-radius: calc(.25rem - 1px);
border-top-right-radius: calc(.25rem - 1px);
}
.card-img-caption .card-img-top {
z-index: 0;
}
.card-img-caption .card-text {
text-align: center;
width: 100%;
margin: 33% 0;
position: absolute;
z-index: 1;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<div class="card" style="width: 20rem;">
<div class="card-img-caption">
<p class="card-text">Test</p>
<img class="card-img-top" src="http://placehold.it/130x100" alt="Card image cap">
</div>
<div class="card-body">
<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>
</div>
</div>
We're encapsulating the .card-img-top
image inside a new wrapper called .card-img-caption
and then applying some positioning and z-index
so that the image always lays beneath the text.
You'll likely want to fiddle with the margin
on .card-img-caption .card-text
as the 33%
being used here is more of a magic number than something more elegant.
If you know the dimensions of the image you're using as a background though; a smarter move might be to do just that... use a background-image
.
I know this is old, but for those that are using Bootstrap 4, there is a native way to do this using the card-img-overlay
class.
<div class="card bg-dark text-white">
<img class="card-img" src="..." alt="Card image">
<div class="card-img-overlay">
<h5 class="card-title">Card title</h5>
<p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
<p class="card-text">Last updated 3 mins ago</p>
</div>
</div>
https://getbootstrap.com/docs/4.0/components/card/#image-overlays
Try like this:
#container {
height: 400px;
width: 400px;
position: relative;
}
#image {
position: absolute;
left: 0;
top: 0;
}
#text {
z-index: 100;
position: absolute;
color: white;
font-size: 24px;
font-weight: bold;
left: 150px;
top: 350px;
}
<div id="container">
<img id="image" src="http://www.noao.edu/image_gallery/images/d4/androa.jpg" />
<p id="text">
Hello World!
</p>
</div>
Here is my solution using the bootstrap img-wrapper and img-overlay classes.
<div class="card">
<div class="img-wrapper">
<img class="card-img-top" src="images/mytopimage.png"/>
<div class="img-overlay"> <h2>Text Over Image</h2> </div>
</div>
<div class="card-body">
<h2 class="card-title">My Card</h2>
<p class="card-text">My Card Text</p>
</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With