How to align content of a div to the bottom

后端 未结 26 2557
挽巷
挽巷 2020-11-22 01:13

Say I have the following CSS and HTML code:

26条回答
  •  后悔当初
    2020-11-22 01:53

    If you have multiple, dynamic height items, use the CSS display values of table and table-cell:

    HTML

    
    
    
      
    my bottom aligned div 1
    my bottom aligned div 2
    my bottom aligned div 3

    CSS

    html,
    body {
      width: 100%;
      height: 100%;
    }
    .valign {
      display: table;
      width: 100%;
      height: 100%;
    }
    .valign > div {
      display: table-cell;
      width: 100%;
      height: 100%;
    }
    .valign.bottom > div {
      vertical-align: bottom;
    }
    

    I've created a JSBin demo here: http://jsbin.com/INOnAkuF/2/edit

    The demo also has an example how to vertically center align using the same technique.

提交回复
热议问题