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.


Aspect ratios

I have been working on a Website and have been struggling with Responsive Web Design.

I have 12 squares laid out next to eachother vertically and they're all the same width and height as eachother; they're all made using css.

As I decrease the width of the browser window, I want all of these squares to decrease in size fluidly (possibly as a percentage) but I want the shape to remain the same (equal height and width).



^ An example of the kind of layout.

2 Answers

Emily Kelton
Emily Kelton
3,626 Points

You can give your .square(s) a height and width in a relative measurement, like ems or rems. That should work.

Doesn't appear to be working. =(

Emily Kelton
Emily Kelton
3,626 Points

Try this instead: .square { border: 1px solid black; width: 20%; background-color: red; display: inline-block; padding-bottom: 20%; }

So long as your padding-bottom is equal to the width, they should be squares.