This cannot be done with CSS alone. Using jQuery you can achieve this by doing
var chld = $('.child').width();
$('.child').css({'height':chld+'px'});
Check working example at http://jsfiddle.net/4Jnfq/
A CSS only solution can be found here on the last "Resize with content" update.
Although it applies for circles, you can remove the border-radius: 50% to make it work for squares.