Scrollbar without fixed height/Dynamic height with scrollbar

后端 未结 10 1486
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 22:24

I have this HTML structure:

Dynamic height without scrollbar

相关标签:
10条回答
  • 2020-12-02 22:47

    You will have to specify a fixed height, you cannot use 100% because there is nothing for this to be compared to, as in height=100% of what?

    Edited fiddle:

    http://jsfiddle.net/6WAnd/4/

    0 讨论(0)
  • 2020-12-02 22:54

    With display grid you can dynamically adjust height of each section.

    #body{
      display:grid;
      grid-template-rows:1fr 1fr 1fr;
    }
    

    Add the above code and you will get desired results.

    Sometimes when many levels of grids are involved css wont restrict your #content to 1fr. In such scenarios use:

    #content{
      max-height:100%;
    }
    
    0 讨论(0)
  • 2020-12-02 22:57

    The JS answer to this question is:

    http://jsfiddle.net/6WAnd/20/

    or something similar

    0 讨论(0)
  • 2020-12-02 22:58
     <div id="scroll">
        <p>Try to add more text</p>
     </div>
    

    here's the css code

    #scroll {
       overflow-y:auto;
       height:auto;
       max-height:200px;
       border:1px solid black;
       width:300px;
     }
    

    here's the demo JSFIDDLE

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