Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Question on CSS viewport width/height

I have 3 questions related to viewport;

  1. Do document.documentElement.clientWidth and -Height always gives the viewport dimensions, regardless of the dimensions of the element ?

  2. Can we both get and set width for the html element ? If yes, can this be done both using CSS and JS ?

  3. Is there a CSS exception to the rule that "document.documentElement.clientWidth and -Height still gives the dimensions of the viewport, and not of the element "

like image 598
copenndthagen Avatar asked Mar 27 '26 00:03

copenndthagen


1 Answers

  1. it should always return the dimension of the viewport regardless of styles applied to the html element.

  2. you can't set it. As this would require the browser-window to resize too. You can resize the window using JS but you shouldn't do that. You can change the height and width of the html element with css, but that doesn't change the clientWidth.

  3. if you want to get the actual width of the html element use document.documentElement.offsetWidth

mobile is a bit of a different story.

like image 167
Gerben Avatar answered Mar 28 '26 18:03

Gerben



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!