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 CSS Layout Techniques Positioning Schemes Absolute Centering

How can we get this technique to work such that the parent has a 'flexible' height for responsive behavior?

I need to use this technique with <img> (need to put in as HTML content), and I also need there to be responsive behavior.

Therefore, the relatively positioned parent, needs to be able to adjust its height with relation to the height of it's tallest child and/or in relation to the height of the container.

Something like this:

.carousel { background: #dfe2e4; background: url(../images/bg/port-bg.png) no-repeat top center; background-size: contain; margin: 4px; min-height: 221px; position: relative; }

.carousel img { margin: auto; width: 100%; /* 'Absolute' centering. */ position: absolute; top: 0; right: 0; bottom: 0; left: 0; }

1 Answer

You can try height: 100%; or height: auto; Hope this helps!