Div height 100% and expands to fit content

后端 未结 15 804
攒了一身酷
攒了一身酷 2020-11-29 15:51

I have a div element on my page with its height set to 100%. The height of the body is also set to 100%. The inner div has a background and all that and is different from t

相关标签:
15条回答
  • 2020-11-29 16:21

    Old question, but in my case i found using position:fixed solved it for me. My situation might have been a little different though. I had an overlayed semi transparent div with a loading animation in it that I needed displayed while the page was loading. So using height:auto / 100% or min-height: 100% both filled the window but not the off-screen area. Using position:fixed made this overlay scroll with the user, so it always covered the visible area and kept my preloading animation centred on the screen.

    0 讨论(0)
  • 2020-11-29 16:23

    Set the height to auto and min-height to 100%. This should solve it for most browsers.

    body {
      position: relative;
      height: auto;
      min-height: 100% !important;
    }
    
    0 讨论(0)
  • 2020-11-29 16:23

    Just add these two line in your css id #some_div

    display: block;
    overflow: auto;
    

    After that you will get what your are looking for !

    0 讨论(0)
  • 2020-11-29 16:24

    use flex

    .parent{
        display: flex
    }
    
    .fit-parent{
        display: flex;
        flex-grow: 1
    }
    
    0 讨论(0)
  • 2020-11-29 16:29

    I'm not entirely sure that I've understood the question because this is a fairly straightforward answer, but here goes... :)

    Have you tried setting the overflow property of the container to visible or auto?

    #some_div {
        height:100%;
        background:black; 
        overflow: visible;
        }
    

    Adding that should push the black container to whatever size your dynamic container requires. I prefer visible to auto because auto seems to come with scroll bars...

    0 讨论(0)
  • 2020-11-29 16:29

    Even you can do like this

    display:block;
    overflow:auto;
    height: 100%;
    

    This will include your each dynamic div as per the content. Suppose if you have a common div with class it will increase height of each dynamic div according to the content

    0 讨论(0)
提交回复
热议问题