So basically, I want to draw a line from point A (0vh|0vw) to point B (50vh|50vw).
I first thought of using a div with a border and a height of 1 PX that I rotated to get the effect.
The problem with that is that if the site size changes when the user is using an unusual monitor or when he resizes the window, the rotation angle is not right anymore.
So what I want is to draw a line from a fixed point A to a fixed point B, automatically changing the degree of rotation when the site is resized.
4
Answers
Try use 100vh,100vw to body and inside use only px,so the screen will be adapitate but the size of stick no
As manassehkatz stated, you could use an SVG.
You could also use a canvas, but it requires you to implement custom resizing and rendering.
I’d recommend using an
hr
rather than adiv
(since it’s basically just a rotated horizontal rule) but: yeah, you can totally do this with CSS. However, it needs some functions that at the time of this answer only work in Safari, and Firefox: the CSS sqrt() and atan2 functions.We can set the width of our
hr
to your triangle’s hypotenuse, and set the rotation usingatan2
(for more info on this rather special function, see its wikipedia article. It’s so important, it’s literally baked into CPUs as a lowest-level machine instruction) to compute an angle given a distance and rise:Of course, using SVG would be a heck of a lot easier, and would have better compatibility =D
A simple (simplistic) way of doing this in CSS is to clip a div which is covering the whole viewport.
Here’s an example: