How to align content of a div to the bottom

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

Say I have the following CSS and HTML code:

26条回答
  •  -上瘾入骨i
    2020-11-22 02:05

    Relative+absolute positioning is your best bet:

    #header {
      position: relative;
      min-height: 150px;
    }
    
    #header-content {
      position: absolute;
      bottom: 0;
      left: 0;
    }
    
    #header, #header * {
      background: rgba(40, 40, 100, 0.25);
    }

    But you may run into issues with that. When I tried it I had problems with dropdown menus appearing below the content. It's just not pretty.

    Honestly, for vertical centering issues and, well, any vertical alignment issues with the items aren't fixed height, it's easier just to use tables.

    Example: Can you do this HTML layout without using tables?

提交回复
热议问题