Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot scroll to element if position absolute and overflow-x hidden specified

I have animated ng-view. I'm using slideup animation, which requires absolute position of elements and also overflow-x: hidden to clip the content. In one sub-page I have to use scrollTo element functionality, but it doesn't work if both 2 values are specified. Here is a main ng-view class which is required for correct animations

.wrapper {
    position: absolute !important; 
    left: 0;
    top: 0;
    height: 100%;
    min-height: 100%;
    min-width: 100%;
    overflow-x: hidden;
  }

And structure:

<div class="wrapper ng-view-div">
 <nav>
        <ul>
          <li><a href du-smooth-scroll="section-1" du-scrollspy>Section 1</a></li>
            <li><a href du-smooth-scroll="section-2" du-scrollspy>Section 2</a></li>
            <li><a href du-smooth-scroll="section-3" du-scrollspy>Section 3</a></li>
        </ul>
    </nav>

<section id="section-1" style="background-color: red">
  C
</section>
<section id="section-2"  style="background-color: blue">
  C
</section>
<section id="section-3"  style="background-color: green">
  C
</section>
</div>

I prepared plnkr to easily show how it looks like for now. Is there any other way to achieve scroll working but with this two values ?

like image 727
kxyz Avatar asked Feb 27 '16 22:02

kxyz


People also ask

Does overflow hidden work on position absolute?

Adding the parent element with position:relative; solves the problem. In order to have absolute positioned “wrapper img” work with the property of overflow: hidden, position the parent element “wrapper” to relative.

How to solve overflow error in CSS?

To change this, set the min-width or min-height property.” This means that a flex item with a long word won't shrink below its minimum content size. To fix this, we can either use an overflow value other than visible , or we can set min-width: 0 on the flex item.

What does overflow-x hidden do?

The overflow-x CSS property sets what shows when content overflows a block-level element's left and right edges. This may be nothing, a scroll bar, or the overflow content.

How to restrict overflow in CSS?

Use overflow: hidden instead. Use overflow-x : scroll and overflow-y : hidden , or overflow: scroll hidden instead.


1 Answers

Here, height:100% in the wrapper CSS class creates an issue. Please use the wrapper CSS class below.

.wrapper {
    position: absolute !important; 
    left: 0;
    top: 0;
    min-height: 100%;
    min-width: 100%;
    overflow-x: hidden;
}
like image 170
Hardik Patel Avatar answered Oct 03 '22 06:10

Hardik Patel