1

I don't why I set overflow: hidden, my div is still scrollable. Pls tell me why

.myDiv {
    position: relative;
    width: 100%;
    min-height: 100vh;
    display: flex;
    align-items: center;
    flex-direction: column;
    overflow: hidden;
}

Adding html structure

  <div className="myDiv">
     <div className='imgBx'>
        {/* img content inside */}
     </div>
     <div className='post'>
        {/* post content inside */}
     </div>
  </div>
Zombani
  • 95
  • 1
  • 8
  • 1
    Sometimes, you need to make sure that the parent element is not being scrolled. You need to provide some HTML structure so others can understand the hierarchy correctly. Also [this](https://stackoverflow.com/questions/3970455/how-to-make-the-overflow-css-property-work-with-hidden-as-value) might help you. – akaAbdullahMateen Jul 18 '22 at 04:24
  • I've added it, you can check out – Zombani Jul 18 '22 at 04:50
  • Please provide a snippet we can run. You can pick up the actual HTML and CSS from browser dev tools inspect facility. – A Haworth Jul 18 '22 at 05:55
  • Ah, you’ve only given it a min height so all the content will be shown. It’ll be some parent (possibly body) that is being scrolled. – A Haworth Jul 18 '22 at 05:57
  • I don't get it, can you say more particularly – Zombani Jul 18 '22 at 06:05
  • Even if I change the height to some specific px, it doesn't matter – Zombani Jul 18 '22 at 06:08

2 Answers2

1

You can overflow: hidden !important; for avoid other ovverriden styles

.myDiv {
    position: relative;
    width: 100%;
    min-height: 100vh;
    display: flex;
    align-items: center;
    flex-direction: column;
    overflow: hidden !important;
}
0

For allowing scroll bar. These two CSS properties can be used to hide the scrollbars:

overflow-y: hidden; // hide vertical
overflow-x: hidden; // hide horizontal