Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XHTML HTML element with 100% height causing scrollbars

In my CSS file I use this:

html,body{height:100%;padding:0;margin:0;border:0;}

Which causes a vertical scrollbar to appear on IE8, Chrome 5 and Mozilla 3.6, all latest version.

Also, the document is empty, it only has the html, head and body tags so nothing is going out of screen to cause that.

Setting overflow:hidden; on the html element will completly stop scrolling on the page.

How can I make it go away please but also keep scrolling when content is higher than display height?

Thank you.

like image 574
Francisc Avatar asked Aug 24 '10 13:08

Francisc


People also ask

Which HTML element is causing the vertical scroll bar?

Right click on it and select inspect element. That should give you the information you need.

What are the two types of scrollbars?

There are two types of scroll bar controls: HScrollBar for horizontal scroll bars and VScrollBar for vertical scroll bars. These are used independently from each other.

Why are there two scrollbars HTML?

You're basically getting a double scrollbar because your giving the body min-height of 100vh AND setting an overflow. It appears this was done to keep the menu in the correct position on mobile devices.


1 Answers

I need 100% height in a XHTML document so that I can have div elements with 100%.

Anyway, I found the answer:

This problem only occurs when the top most element has a top margin. It seems that that top margin gets added to the 100% height making it higher and causing the scrollbar.

So either use padding-top to space the top most element or use a with no top margin between the tag and the next element with a top margin.

like image 185
Francisc Avatar answered Oct 22 '22 14:10

Francisc