Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

How to make images overlap each other by css

I have images, whose got very less content and have a lot of background, which is not required. Since the images has a lot of background, there are taking a lot of space. The structure of the document is image1, image2. Image1 is taking a lot of space (backgound), I want the image 2 to occupy the background space of image 1. This is the normal situation http://ctrlv.in/561984 This is intended http://ctrlv.in/561968

4 Answers

John Reed
John Reed
12,911 Points

I would recommend using position relative and absolute values to achieve your desired results. Here's a good article on learning position with css in 10 steps http://www.barelyfitz.com/screencast/html-training/css/positioning/

You can add margin between the elements , or position the element you want to move relative to its parent element. The achieved with the position property.

Sam Baines
Sam Baines
4,315 Points

Hi Vamsi - you should be able to achieve this with the margin property on image 2 but making the margin negative in numbers - however negative margins are not best practice.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

You could also try setting to to a relative position and using the bottom keyword so the second image will push from the top.