How to dynamically increase the height of a
based on the contents?

后端 未结 4 1271
终归单人心
终归单人心 2021-01-20 11:52

I have a div on a page that I need to put content into. Sometimes the content is a few lines high, and sometimes the content is more than the screen height with varying size

相关标签:
4条回答
  • 2021-01-20 12:02

    Don't specify a height, and the div will automatically resize with the contents.

    If you need a minimum size, there is a CSS property called min-height that sets the minimum height of the div.

    0 讨论(0)
  • 2021-01-20 12:06

    The height should resize automatically, and the bottom DIV should be pushed down in accordance with this height.

    0 讨论(0)
  • 2021-01-20 12:11

    Resizing vertically to fit the content is the expected behavior. If you have specified floats somewhere in your css you may need to clear them:

    <div style="clear:both;"></div>
    
    0 讨论(0)
  • 2021-01-20 12:18

    #MainContentArea will always expand dynamically since its height is assigned as auto.

    Since both have the same width, #BottomContentArea will be pushed down.

    Instead of percentage, use exact widths.

    <div id="MainContentArea" style="float:left;height:auto;width:100%;">
    <!-- my content -->
    </div>
    
    <div id="BottomContentArea" style="float:left;height:auto;width:100%;s">
    <!-- pre-existing content -->
    </div>
    
    0 讨论(0)
提交回复
热议问题