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> 
6
  • 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 might help you. Commented Jul 18, 2022 at 4:24
  • I've added it, you can check out Commented Jul 18, 2022 at 4:50
  • Please provide a snippet we can run. You can pick up the actual HTML and CSS from browser dev tools inspect facility. Commented Jul 18, 2022 at 5: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. Commented Jul 18, 2022 at 5:57
  • I don't get it, can you say more particularly Commented Jul 18, 2022 at 6:05

2 Answers 2

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; } 
Sign up to request clarification or add additional context in comments.

7 Comments

I've tried but it still doesn't work
also add height or width to .imgBx and .post class
if you want to stop scroll for inner div then you have to add on overflow: hidden !important; .imgBx and .post class
Is it necessary to set height for imgBx and post, I always set min-height: 300px
if .imgBx and .post are scrollable, then you must have to set Height & width
|
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 

1 Comment

overflow: hidden is equivalent to this. So for the same reason, the OP's code does not hide scrollbars, yours won't either.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.