How to align content of a div to the bottom

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

Say I have the following CSS and HTML code:

26条回答
  •  无人共我
    2020-11-22 01:42

    Here is another solution using flexbox but without using flex-end for bottom alignment. The idea is to set margin-bottom on h1 to auto to push the remaining content to the bottom:

    #header {
      height: 350px;
      display:flex;
      flex-direction:column;
      border:1px solid;
    }
    
    #header h1 {
     margin-bottom:auto;
    }

    We can also do the same with margin-top:auto on the text but in this case we need to wrap it inside a div or span:

    #header {
      height: 350px;
      display:flex;
      flex-direction:column;
      border:1px solid;
    }
    
    #header span {
     margin-top:auto;
    }

提交回复
热议问题