How to align content of a div to the bottom

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

Say I have the following CSS and HTML code:

26条回答
  •  猫巷女王i
    2020-11-22 01:53

    You don't need absolute+relative for this. It is very much possible using relative position for both container and data. This is how you do it.

    Assume height of your data is going to be x. Your container is relative and footer is also relative. All you have to do is add to your data

    bottom: -webkit-calc(-100% + x);
    

    Your data will always be at the bottom of your container. Works even if you have container with dynamic height.

    HTML will be like this

    CSS will be like this

    .container{
      height:400px;
      width:600px;
      border:1px solid red;
      margin-top:50px;
      margin-left:50px;
      display:block;
    }
    .data{
      width:100%;
      height:40px;
      position:relative;
       float:left;
      border:1px solid blue;
      bottom: -webkit-calc(-100% + 40px);
       bottom:calc(-100% + 40px);
    }
    

    Live example here

    Hope this helps.

提交回复
热议问题