-1

I am drawing a canvas with a javascript function and it always aligns to windows size. I want to have a

<div>...</div>

Element overlay a canvas and be vertically and horizontically centered.

The only thing I came up was

position:absolue;

But then again

top:0;
left:0;
bottom:0;
right:0;

Only centers my element horizontically not vertically.

So I've changed it to.

 left:calc(50% - *divwidth*/2);
 top:calc(50% - *divheight*/2);

But it is not optimal and doesnt work for various windows sizes.

I think that this might not even be possible with pure css, so I am happy to use JS but how do I do that?

digitalsuite.net
  • 339
  • 6
  • 20

2 Answers2

0

Have you tried giving the div overlay a height and width of 100%?

fishstix
  • 11
  • 1
0

The answer from Adrian P. in Position div to center of visible area worked surprisingly well for my case and a fixed width height div. I will be using this until I find a better one.

digitalsuite.net
  • 339
  • 6
  • 20