Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 90,705 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.