Pure CSS Solution - Square Elements?

Trey Keown picture Trey Keown · Dec 13, 2012 · Viewed 40.6k times · Source

If I have a <div> with a relative width (such as width: 50%), is there a simple way to make it have the same width as it does height without resorting to JavaScript?

Answer

Tomasz Kowalczyk picture Tomasz Kowalczyk · Oct 18, 2013

It is actually possible to achieve it with this neat trick i found at this blog

#square {
   width: 100%;
   height: 0;
   padding-bottom: 100%;
}

Hope that helps