What i’m looking for,is a way to set the width of the body same as the clients window’s,using JAVA.
This code i’ve borrowed from W3S,but its not working in my case –
function body_width(w)
{
var w = window.innerWidth
|| document.documentElement.clientWidth
|| document.body.clientWidth;
var x = document.body;
x.style.width = w;
}
window.onload = body_width(w);
Also i’ve gave "style="width:;" "
to the body
Have you tried using screen.availWidth and screen.availHeight?
The screen.availHeight property returns the height of the visitor’s screen, in pixels, minus interface features like the Windows Taskbar.
The screen.availWidth property returns the width of the visitor’s screen, in pixels, minus interface features like the Windows Taskbar.
It could be done easily with Viewport-Percentage Lengths:
The viewport-percentage lengths are relative to the size of the initial containing block. When the height or width of the initial containing block is changed, they are scaled accordingly.
HTML
And CSS
That is all you need.
Here is JSFiddle example.
Try to set width in % :
not
window.onload = body_width(w);
its
window.onload = body_width;
This option worked out perfectly.
Thanks 2 ivarz_LV
When I tested, using
won’t work. Try using this in
style
:I figured using
vh
would work better.