Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make height equal width with css [duplicate]

How to make height equal width with css.

I have HTML like that :

<div style="width:900px;height:200px;">
<a style="display:block; float:left; width:35%; background:green"></a>
</div>

Now, I'd like to make height of a element equal width (35%). How can I do that? Thank your help.

like image 321
Hai Tien Avatar asked Sep 22 '13 17:09

Hai Tien


1 Answers

Well I have that:

HTML:

<div class='box'> 
    <div class='content'>Aspect ratio of 1:1</div> 
</div>

CSS:

.box{
    background:#000;
    position: relative;
    width: 50%;     /* desired width */
}
.box:before{
    content: "";
    display: block;
    padding-top: 100%;  /* initial ratio of 1:1*/
}

JSFiddle: http://jsfiddle.net/wGszc/

http://www.mademyday.de/css-height-equals-width-with-pure-css.html

You can adapt it to your needs...

And... A little search in google doesn't hurt: https://www.google.com/search?q=make+height+iquals+to+width

like image 139
Seazoux Avatar answered Sep 24 '22 09:09

Seazoux