Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Liquid layout: avoid change in body width due to vertical scrollbar

Tags:

html

css

I have implemented liquid layout for my website. I have set width of body tag to 100%.

<html>
<head>
</head>

<body>
    <div id="container">
        some content
    </div>
</body>

body
{
   margin: 0;
   padding: 0;
   width: 100%;
}

For some pages vertical scrollbar is displayed. Because of which body tag width reduces by 16px. I need to set body width in such a way that display of scrollbar doesn't affect it.
I have tried following but it didn't work with FF9. :

 body{
    width: -moz-calc(100% - 16px);
}

Can any body suggest a way to achieve this?

like image 729
Nilesh Avatar asked Feb 28 '12 15:02

Nilesh


People also ask

Does viewport width include scrollbar?

Many assume that width: 100vw is the same as width: 100% . This is true on a page that doesn't scroll vertically, but what you might not realize is that the viewport actually includes the scrollbars, too.

How do I make my vertical overflow scroll?

For vertical scrollable bar use the x and y axis. Set the overflow-x:hidden; and overflow-y:auto; that will automatically hide the horizontal scroll bar and present only vertical scrollbar. Here the scroll div will be vertically scrollable.

What is the difference between the vertical and horizontal scrollbars?

A horizontal scroll bar enables the user to scroll the content of a window to the left or right. A vertical scroll bar enables the user to scroll the content up or down.


1 Answers

One way to work around this is to make sure scroll bars are always present. You can then style your pages with confidence that they're not going to shift left and right.

html,body
{
 height:101%;
}

You can also do:

html {
       overflow-y: scroll;
}

(I don't think the overflow method works with Opera though)

like image 162
Jamie Dixon Avatar answered Sep 22 '22 11:09

Jamie Dixon