
Is it possible to get current distance between left and right? Not full width.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
window.innerWidthcan be used to get the browser window viewport width, including scrollbars (if present and rendered).There’s also
document.body.clientWidthwhich does not include scrollbar, margin, border, or padding – the latter 3 are irrelevant if you havemargin:0; padding:0;and no border set to thebody, which is the case when using a reset stylesheet. Otherwise you just have to compensate for these.Notes:
clientWidth, even though being supported by all major browsers (IE 5.5+, FF3+, Chrome, Opera, Safari), has never been defined by W3C so browser support may vary.window.innerWidthhas a W3C spec, but is not supported in IE < 9.Here’s a fiddle comparing both.
Edit:
window.innerWidthis not supported in IE<9, so using a mix ofinnerWidthandclientWidth(for older IE) is probably the best approach:Also, even though
clientWidthis not standardized by the W3C, it is supported in all major browsers so many people find it reliable enough to use solelyclientWidthinstead of the W3C standardinnerWidth.If not including the scrollbar is important for your use-case then
clientWidthcan be used as the first/only option:Ensure that
bodyhasmargin:0andpadding:0in case you use the above.