scroll property in a child element of a parent div whose position is fixed

Parveez Ahmed

I here want to know a simple fact:

<div style="position:fixed;height:100%;width:100%;overflow:scroll">
 <div style="position:relative">Large content</div>
</div>

Its fine.Again (overflow is placed within the child's style):

<div style="position:fixed;height:100%;width:100%;">
 <div style="position:relative;overflow:scroll">Large content</div>
</div>

It doesn't scroll.

I simply want to know the simple reason. Anyone mind to tell me?

Nick Andriopoulos

The reason is that your parent gets the window height, and is limited to that. However, the child is not limited height-wise, and all the content is visible inside it.

For instance, if you have a text that is 2000px in height, on a 1920x1080 screen, the parent will have a height of ~1000px (visible area), but the child (with the content) will have 2000px in height and scrolling is not required. You can simply add a height or max-height style for the child, which will allow you to use scrolling.

This fiddle is your code, with 15 paragraphs of lorem ipsum text. You can inspect it to see the above.

This fiddle on the other hand adds a max-height: 95% to the child element, and scrolling is possible.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to position a child element at the bottom of a fixed position parent

From Dev

Keep element position fixed to parent using transform on scroll

From Dev

Make child div larger than fixed position parent div

From Dev

position fixed in child element but sync parents x scroll with child elements left position

From Dev

jQuery position DIV fixed on scroll

From Dev

div image position fixed + scroll

From Dev

CSS position fixed div still displayed in respect to parent element

From Dev

How to set a div percentage width with a fixed position based on the parent element

From Dev

scroll and position: fixed inside overflow: scroll div

From Dev

Scroll parent to top of child element

From Dev

Horizontal scroll only if child element's width property exceeds parent element's max-width property

From Dev

Child of position: fixed; won't scroll

From Dev

Child with position:fixed scrolls with position:fixed, overflow:auto parent

From Dev

Child with position:fixed scrolls with position:fixed, overflow:auto parent

From Dev

Fixed div outside of parent element

From Dev

Freeze element (position:fixed) for specific scroll range

From Dev

Scroll content of fixed element along with parent

From Dev

How to scroll div with page without position: fixed?

From Dev

jQuery position DIV fixed at top on scroll

From Dev

jQuery position DIV fixed at top on scroll

From Dev

make div (position:fixed) scroll horizontally

From Dev

How to make position fixed div scroll horizontally?

From Dev

Scroll a fixed position div to its bottom and then stop

From Dev

How can I make a fixed div go across parent element without covering vertical scroll?

From Dev

Element position fixed is related to parent instead to the viewport

From Dev

DIV CSS Layout - fixed position expand parent

From Dev

Force div within fixed element to scroll horizontally

From Dev

CSS selector for a child element whose parent element has a certain class

From Dev

Child Div overflow x - y and scroll on parent

Related Related

  1. 1

    How to position a child element at the bottom of a fixed position parent

  2. 2

    Keep element position fixed to parent using transform on scroll

  3. 3

    Make child div larger than fixed position parent div

  4. 4

    position fixed in child element but sync parents x scroll with child elements left position

  5. 5

    jQuery position DIV fixed on scroll

  6. 6

    div image position fixed + scroll

  7. 7

    CSS position fixed div still displayed in respect to parent element

  8. 8

    How to set a div percentage width with a fixed position based on the parent element

  9. 9

    scroll and position: fixed inside overflow: scroll div

  10. 10

    Scroll parent to top of child element

  11. 11

    Horizontal scroll only if child element's width property exceeds parent element's max-width property

  12. 12

    Child of position: fixed; won't scroll

  13. 13

    Child with position:fixed scrolls with position:fixed, overflow:auto parent

  14. 14

    Child with position:fixed scrolls with position:fixed, overflow:auto parent

  15. 15

    Fixed div outside of parent element

  16. 16

    Freeze element (position:fixed) for specific scroll range

  17. 17

    Scroll content of fixed element along with parent

  18. 18

    How to scroll div with page without position: fixed?

  19. 19

    jQuery position DIV fixed at top on scroll

  20. 20

    jQuery position DIV fixed at top on scroll

  21. 21

    make div (position:fixed) scroll horizontally

  22. 22

    How to make position fixed div scroll horizontally?

  23. 23

    Scroll a fixed position div to its bottom and then stop

  24. 24

    How can I make a fixed div go across parent element without covering vertical scroll?

  25. 25

    Element position fixed is related to parent instead to the viewport

  26. 26

    DIV CSS Layout - fixed position expand parent

  27. 27

    Force div within fixed element to scroll horizontally

  28. 28

    CSS selector for a child element whose parent element has a certain class

  29. 29

    Child Div overflow x - y and scroll on parent

HotTag

Archive