I had this idea for making elements as high as they are wide with just css and html. A requirement was that the text inside would be aligned in the center, horizontally and vertically even across multiple lines.
So based on some other peoples thoughts on this ( http://www.mademyday.de/css-height-equals-width-with-pure-css.html )
I made the following HTML:
<span class='box'>
<span class='height'></span>
<span class='content'>This is just a longer text to demonstrate multiple lines being centered.</span>
</span>
Accompanied by the following CSS:
.box {
/* width */
width: 25%;
display: table;
}
.height {
display: table-cell;
/* The height for this item will become this %-age of the width of the .box, so this is 1:1 ratio */
padding-top: 100%;
}
.content {
display: table-cell;
vertical-align: middle;
text-align: center;
}
Here's a fiddle: http://jsfiddle.net/cjxB7/.
This seems to work just fine, however, when resizing the browser ( especially the longer tekst, with the browser from big to small ) the elements don't keep their ratio.
I've tried this in all major browsers. And they all seem to have this caveat.
What am I missing? Does this have something to do with the way tables work?
Please let me know if you need more to go on. Thanks!