I've just started playing with Twitter Bootstrap and I'm trying to make an image in a row overlap the contents below it. How can I accomplish that? I tried giving the contents below a negative margin but that doesn't seem to work in Chrome dev tools. Here's a link to what I currently have, but just to summarize:
<div class="container" role="main">
<div class="row">
<div class="col-md-1">
</div>
<div class="col-md-3">
<a href="#" class="thumbnail">
<img src="http://placehold.it/252x136" alt="...">
</a>
</div>
<div class="col-md-8">
</div>
</div>
<div class="jumbotron">
</div>
</div>
As you can see the <img>
pushes the entire jumbotron down. I'd like it to overlap instead until the screen size collapses (responsively) and then the image should no longer overlap in that case.
UPDATE
I ended up combining @JoshC and @Adrian's solutions for the best of both:
@media (min-width: 992px) {
#overlap {
height: 70px;
}
}
You can use the CSS position property in combination with the z-index property to overlay an individual div over another div element. The z-index property determines the stacking order for positioned elements (i.e. elements whose position value is one of absolute , fixed , or relative ).
You can apply the CSS position:relative; and then specify an offset such as top:-50px;left:-20px; which would shift the element 20 pixels to the left and 50 pixels up. You can also specify right and bottom and use positive or negative values.
You could absolutely position the .col-md-3.img
element, and then float the .col-md-8.nav
to the right. I added some classes to the elements and then placed the styling in a media query to ensure this doesn't conflict with any mobile/tablet styling. It seems to work well on all screen sizes.
UPDATED EXAMPLE HERE - FULL SCREEN EXAMPLE
@media (min-width: 992px) {
.col-md-3.img {
position: absolute;
text-align: center;
}
.col-md-3.img .thumbnail {
display:inline-block;
}
.col-md-8.nav {
float: right;
}
}
Add text-align:center
to center the .thumbnail
element, which is now also inline-block
to fix background-related issues that result from the absolute positioning.
You can accomplish that by adding height to your row. In the demo below, I added an id="overlap" to the row.
CSS
#overlap{
height:90px;
}
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