Here's one hack that you can use: a quirk with CSS is that the top and bottom paddings/margins, when set to percentages, are computed based on the width of the parent element, not its height.
So, if you want a square div, which is, say, 50% the width of its parent element. To make it square, you simply set it's bottom padding to 50%, too.
The thing is that you have to adjust the padding percentage based on the div's width. If the div's width is set to 75% of parent, for example, to get a square you will need to use a bottom padding of 75%.
div {
background-color: #eee;
width: 50%;
height: 0;
margin-bottom: 40px;
}
.square {
padding-bottom: 50%; /* (50%*1) */
}
.landscape {
padding-bottom: 37.5%; /* (50%*(3/4)) */
}
.portrait {
padding-bottom: 66.6667%; /* (50%*(4/3)) */
}
Here's a proof-of-concept fiddle: http://jsfiddle.net/teddyrised/Vsj33/