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

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).

Help?

http://s27.photobucket.com/user/MaxReinsch/media/Screenshotfrom2015-01-29123126.png.html?sort=3&o=0

^ 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.