Created
September 17, 2024 10:08
-
-
Save EmranAhmed/30ce50ab74aa41fdadfa225c31490d06 to your computer and use it in GitHub Desktop.
Get the screen width & height by CSS Only without JavaScript.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
- https://codepen.io/t_afif/pen/ExBVLBW | |
- https://css-tip.com/screen-dimension/ | |
*/ | |
@property --_w { | |
syntax: '<length>'; | |
inherits: true; | |
initial-value: 100vw; | |
} | |
@property --_h { | |
syntax: '<length>'; | |
inherits: true; | |
initial-value: 100vh; | |
} | |
:root { | |
--w: tan(atan2(var(--_w),1px)); /* screen width */ | |
--h: tan(atan2(var(--_h),1px)); /* screen height*/ | |
/* The result is an integer without unit */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment