My child Div Cannot scroll to the bottom


My child Div Cannot scroll to the bottom



I'm a beginner in HTML and CSS and I've encountered a problem.



I tried to look for some solutions, but I still cannot manage to fix my problem.



My child Div(child of the midtop div) cannot be scrolled to the bottom, which makes the last submit button invisible if I add more tables to it.



I'm not really sure what is the root cause of the problem.



The structure of my divs look like this:



wrapper



header



midtop



firstQ



Thanks in advance.



Here is the link to my code:



https://github.com/erictaur/Course-Query/blob/test-branch/InnoServ/Entry.html



https://github.com/erictaur/Course-Query/blob/test-branch/InnoServ/entrycss.css



Part of my code looks like this




.wrapper {
display: block;
}

#header {
margin: auto;
position: relative;
width: 100%;
height: 200px;
background-color: grey;
transform: translate(-50%, 0%);
left: 50%;
top: 0%;
display: block;
}

#midtop {
margin: auto;
position: relative;
width: 100%;
transform: translate(-50%, 0%);
height: 600px;
left: 50%;
overflow: auto;
display: inline-block;
}

#firstQ {
margin: auto;
width: 80%;
position: absolute;
transform: translate(-50%, -50%);
left: 50%;
top: 50%;
display: inline-block;
}




#child1

Welcome!


#end of header


#child2

#child of midtop


...







...




#I cannot see this button if the table is to long
#end of firstQ
</div> #end of midtop


</div> #end of wrapper(parent)



The Screenshot of my page looks like this



I tried overflow:auto in the parent div with absolute positioning.
Doesn't really seem to work.



Thanks again!





edited. Thank you for telling me. @Pete I hope this helps.
– KHT
Jul 2 at 14:29





Html comments are <!-- comment here --> but your problem is you have positioned the firstQ div absolutely - means it is taken out of the flow of the page and therefore adds no height to midtop (meaning it has nothing to scroll)
– Pete
Jul 2 at 14:32



<!-- comment here -->





@Pete I do know that html comments are <!-- comment here -->. I used "#" just to make code easier to read. (At least that's the case for me. Sorry if that's bothering you.
– KHT
Jul 2 at 15:05





2 Answers
2



As per my comment, your firstQ div cannot be absolutely positioned otherwise your midtop div will not gain any height and therefore the scroll will not work properly.



I would centre firstQ using flex and then your problem should be fixed:




.wrapper {
display: block;
}

#header {
margin: auto;
position: relative;
width: 100%;
height: 200px;
background-color: grey;
transform: translate(-50%, 0%);
left: 50%;
top: 0%;
display: block;
}

#midtop {
margin: auto;
position: relative;
width: 100%;
transform: translate(-50%, 0%);
height: 600px;
left: 50%;
overflow: auto;


display: flex; /* change display type */
flex-direction: column;
justify-content:center; /* vertical centring */
}

#firstQ {
margin: auto; /* remove absolute positioning */
width: 80%;
display: inline-block;
}




#child1

Welcome!


#end of header


#child2

#child of midtop


...






bob

...




#I cannot see this button if the table is to long
#end of firstQ
</div> #end of midtop


</div> #end of wrapper(parent)





I edited my css: as for the midtop div: margin: auto; position: relative; width: 100%; transform: translate(-50%, 0%); height: 600px; left: 50%; overflow: scroll; display: flex; flex-direction: column; /* justify-content: center; */ And found that by adding "justify-content: center", the whole child div is shifted upwards thus making the scrollable areas smaller. as for the firstQ div: margin: auto; width: 80%; position: relative; display: inline-block; Can I ask specifically why shouldn't i position my child div?
– KHT
Jul 2 at 15:28






Then you need to make a proper Minimal, Complete, and Verifiable example that we can work with - I can only edit the code you supply and it works in the snippet I have done
– Pete
Jul 2 at 15:29





Thanks @Pete. I'll try to reproduce the scenario more precisely. Thank you for your answer! Finally solved my problem I've been thinking for some time.
– KHT
Jul 2 at 15:42





Ah ok, glad you solved it. You shouldn't accept my answer if it did not solve it - wait a couple of days and then accept your own :)
– Pete
Jul 2 at 15:44




I've edited my code and everything looked "normal" for now, but I was wondering if there is any way to simplify my code. Since I'm not really sure that the thing I wanted to do required that many lines of code.



It would be of great help if anyone could simplify this pile of code so that it could be a lot more comprehensible. I'm constantly adding and deleting parameters and I'm pretty confused by now.




#child1

Welcome!


#end of header


#child2

#child of midtop


...






bob

...




#I cannot see this button if the table is to long
#end of firstQ
</div> #end of midtop


</div> #end of wrapper(parent)


code for css:

#midtop{
margin: auto;
position: relative;
width: 100%;
transform: translate(-50%, 0%);
height: 600px;
left: 50%;
overflow: scroll;
display: flex;
flex-direction: column;
/* justify-content: center; */ (Not sure why this shrinks the scrollable area)
}

#firstQ{
margin: auto;
width: 80%;
position: relative;
display: inline-block;
}






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

JMeter fails on beanshell imports

Why in node-red my HTTP POST no receive payload from inject?

PHP contact form sending but not receiving emails