Skip to content

Instantly share code, notes, and snippets.

@EmranAhmed
Created September 17, 2024 10:08
Show Gist options
  • Save EmranAhmed/30ce50ab74aa41fdadfa225c31490d06 to your computer and use it in GitHub Desktop.
Save EmranAhmed/30ce50ab74aa41fdadfa225c31490d06 to your computer and use it in GitHub Desktop.
Get the screen width & height by CSS Only without JavaScript.
/**
- 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