Canvas fill the entire screen with css

2

I have my canvas in html5:

<canvas></canvas>

I want the canvas to occupy every available area of the browser, I tried to do this:

canvas{
    display: block;
    width: 100%;
    Height: 100%;
    border: 1px solid #c33;
}

Width is occupying everything, but Height does not occupy everything. Can you do all your browser space?

    
asked by anonymous 24.01.2015 / 18:46

1 answer

2

height: 100% only work if you use position: absolute (or fixed ) or Quirck Mode (not recommended, always use doctype ).

One way to solve it would be like this (in this case I recommend fixed , if you want to hide the rest of the elements):

#meuCanvas {
    display: block;
    width: 100%;
    Height: 100%;
    border: 1px solid #c33;
    position: fixed; /*ou position: absolute;*/
     top: 0;
     left: 0;
}

<canvas id="meuCanvas"></canvas>
    
24.01.2015 / 20:16