Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make an element overlap contents below it using Bootstrap

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;
  }
}
like image 818
Abdullah Jibaly Avatar asked Mar 10 '14 06:03

Abdullah Jibaly


People also ask

How do I make DIV elements overlap?

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 ).

How do you overlap elements in HTML?

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.


2 Answers

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.

like image 192
Josh Crozier Avatar answered Nov 09 '22 03:11

Josh Crozier


You can accomplish that by adding height to your row. In the demo below, I added an id="overlap" to the row.

DEMO

CSS

#overlap{
  height:90px;
}
like image 24
Adrian Enriquez Avatar answered Nov 09 '22 03:11

Adrian Enriquez