31

I have read this SO Post: css overflow-x visible and overflow-y hidden causes scroll bar.

Also I have gone through: http://www.brunildo.org/test/Overflowxy2.html

I want to achieve something as follows:

Overflow

When I tried using following code:

overflow-x: hidden;
overflow-y: visible;

It shows something like following result:
Overflow 2
I dont want the scroll bar to appear.

Does Jquery has any solution for it?

4
  • 23
    Ha, that last line was golden. Commented Apr 12, 2013 at 12:04
  • As you have seen the solution will be done by CSS not by jQuery. If you want to let jQuery do it for you, you will still have to understand the CSS rules for it to set the right code. As far as i know, there is no standard property in jQuery to solve this. Commented Apr 12, 2013 at 12:07
  • 3
    @GrantThomas I thought this question was pretty clear. Commented Apr 12, 2013 at 12:07
  • @BillyMathews Without pictures? In essence, perhaps, but the desired result is invisible to me. Commented Apr 12, 2013 at 12:16

3 Answers 3

7

You can do this with CSS like this:

HTML:

<div class="wrapper">
    <div class="inner">
    </div>
</div>

CSS:

.wrapper{
    width: 400px;
    height: 300px;
}
.inner{
    max-width: 100%;
    overflow-x: hidden;
}

Now your .wrapper div will have overflow: visible; but your .inner div will never overflow because it has a maximum width of 100% of the wrapper div. Note that your wrapper must have an explicitly defined width.

Here is a working jsFiddle

Sign up to request clarification or add additional context in comments.

3 Comments

I used these styles inside of a position: fixed sidebar div and added overflow-y: scroll; to the .wrapper and I could scroll up and down in the fixed div AND have overflow-x because tooltips were spilling out the side a bit.
it works with block or inline blocks. With float or absolute elements (like dropdown menu) it does not works. I have a scroll on y part
This still causes scrolling under a certain line-height threshold (which can be dictated by design).
6

CSS:

.class-div {
   overflow-x: clip;
   overflow-y: visible;
}

The thing with clip is, it restricts all scrolling, even programmatic ones.

Refer: https://developer.mozilla.org/en-US/docs/Web/CSS/overflow

1 Comment

clip is not supported in safari
3

I am not sure if you need something like this with jQuery:

$('.horiz').width($('.container').width());

where .horiz is the horizontal bar and set the width of it to the width of the .container which holds the elements.

With CSS:

HTML Markup

<div class='container'>
    <div class='horiz'></div>
    <div class='vert'></div>
</div>

CSS:

 .container {
    width:320px;
    height:320px;
    border:solid 5px green;
    overflow-x: hidden;
 }
 .horiz{
    width:500px;
    height:30px;
    background:red;
 }
 .vert{
    width:30px;
    height:500px;
    background:yellow;
    position:absolute;
    left:0;
    top:30px;
 }

and output of it:
Check the Output

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.