简体   繁体   中英

Float one image over another with CSS

I am using bootstrap with some simple code. Inside the jumbotron div/container i have 2 images. One aligned left. One aligned right. How do i allow the right image to float over/above the left one on resize of the browser window? Driving me crazy.

<div class="jumbotron">
<div class="container">

<div class="left-image">
<img src="left-image.png">
</div>

<div class="right-image">
<img src="right-image.png">
</div>

</div>
</div>

I thought simple css like this would do it?

.left-image {
float: left;
}
.right-image {
float: right;
z-index: 999;
}

You need to use position: absolute if you want your images to overlap

.left-image{
    position: absolute;
    left: 200px;
}
.right-image{
    position: absolute;
    right: 200px;
    z-index: 5;
}

Edit the left and right properties above to get the positioning to your liking.

Example

I think setting a negative margin right on the left floating element with the amount you want the floating right image to be allowed to overlap. Example...

.left-image {
float: left;
margin-right: -200px;
}

I can't test it right now but I think that should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM