views:

378

answers:

3

Hello, my question is

How can I set overflow hidden in cases where the html go's outside the screen

Right now I have set html {overflow: hidden;} in the head tag off the page. So, it's hidden all the time

In my particular case the errors that I show in the registration process cannot be seen on my 13inch laptop, but I don't want to show the scrollbars all the time.

That's why I want it to set(or unset) based on the fact if there is overflow or not.

What would be the best way?

thanks, Richard

A: 

How about something like this:

<div id="overflowHidden" style="overflow:hidden;">
    <div id="contentContainer">
        Content goes here
    </div>
</div>

Set a height on #overflowHidden and, when the content changes in #contentContainer, check the height compared to that of #overflowHidden and set the overflow attribute on #overflowHidden as appropriate.

Not the most elegant solution, but it would be fairly easy to turn on and off (for testing v. production).

inkedmn
but,I have to take another variable into account here.The fact that I want nothing done (keep hidden), if it fits the screensize.
A: 

Will 'overflow:auto' not suffice?

http://www.w3.org/TR/CSS2/visufx.html

auto:The behavior of the 'auto' value is user agent-dependent, but should cause a scrolling mechanism to be provided for overflowing boxes

cjuk
yes, but I used divs with the left property set to something like minus 700. It will cause the scrollbars always to be shown and that's a problem, - also in my layout maybe, but that's something else.
hmm, maybe rethink your layout strategy? Maybe you are trying to solve a problem which wouldn't exist if your page structure was different. Just a thought. Good luck!
cjuk
yes, I know that, but that will cause more headache then this problem, because I know have it the way I want it.If I can't find find a workaraound, I might do that, or I will move the errorbox upword.
A: 

Would it help if you only set the scrollbar for vertical scrolling?

You could do this using overflow-y: auto; and overflow-x: hidden;

This will show a vertical scrollbar (only when you need it), but will not show a horizontal scrollbar. This way the hidden divs with negative property won't show, even if you decide to show the scrollbars.

ylebre
thanks, that helps. Mayby, I can also do something with document.height() or window.height(), if neccasary. Do you set those with jquery like $('body').css("overflow-y", "auto")??
You could set it with jquery, but I was thinking more in the lines of simple css in the head part of the page. Just like where you have html {overflow: hidden;}, you could put body {overflow-x: hidden; overflow-y: auto;}.
ylebre
I need to do it with jquery, because the top off the page is a template. It worked. Maybe I can detail it more using document.height()