Keep div full square

To keep a div always as a square shape, use code below:

HTML
<container>
    <dummy></dummy>
    <elem><elem>
</container
CSS
container{
    display: inline-block;
    position: relative;
    width: x;
}
dummy{
    margin-top: 100%;
}
elem{
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;   (or right:0; bottom:0)
}
    

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s