I'm building some global button classes for a CSS framework, and I'm wondering if there's any way to set an element's width to be the same as the height without hard-coding it.
Here's an example of how it would work:
HTML
<button class="button square-button">OK</button>
<div class="container">
<button class="button large-button square-button">OK</button>
</div>
CSS
.button {
height: 50px;
padding: 0 20px;
}
.square-button {
width: (always-same-as-height);
padding: 0; // Disable padding so it becomes a square
}
...
.container {
height: 100px
.button {
height: inherit;
}
}
In some scenarios I want to be able to set the height depending on the container height, and have all the buttons with the square-button
class dynamically resize to that height while still staying a perfect square shape.
Is this possible using only CSS?