1

I am trying to make a square with height 100% of the screen only in css. I know that I can do this with JS by calculating the height and applying this to width and height, but I am looking for only css solution.

I have found the following answer but it looks like it makes width 100%. When I tried to make height 100% with

.square{
    height: 100%;
    padding-right: 100%;
    background: red;
}

nothing shows up (take a look at this fiddle). Any idea what is wrong?

Community
  • 1
  • 1
Salvador Dali
  • 214,103
  • 147
  • 703
  • 753

3 Answers3

3

try this http://jsfiddle.net/webtiki/c43QG/

.square{
    height:100vh;
    width:100vh;
}
Amit
  • 1,841
  • 1
  • 19
  • 36
  • 2
    It should be noted that not all browsers support `viewport-units`: http://caniuse.com/viewport-units – Niklas Jun 30 '14 at 08:41
0
  1. You set first time height to 100%, on next line to 0. Why?
  2. you have to add height: 100% to html too

    <style>
    html, body{
        height: 100%;
        margin: 0;
    }
    
    .square{
        height: 100%;
        padding-right: 100%;
        background: red;
    }
    </style>
    <div class="square"></div>
    

    http://jsfiddle.net/9Nxjs/2/

pavel
  • 26,538
  • 10
  • 45
  • 61
-1

I hope this would do http://jsfiddle.net/r8732/

<div class="dummy_class">
  I am height : 100%
</div>

   html, body{
    height:100%;
}

.dummy_class{
    height:100%;
    background-color : red;
}

Add height:100% to your html

Kanishka
  • 85
  • 2
  • 11