Align an element to bottom with flexbox

前端 未结 8 1980
陌清茗
陌清茗 2020-11-22 15:34

I have a div with some children:

heading 1

heading 2

Some

8条回答
  •  孤城傲影
    2020-11-22 16:30

    I just found a solution for this.

    for those who are not satisfied with the given answers can try this approach with flexbox

    CSS

        .myFlexContainer {
            display: flex;
            width: 100%;
        }
    
        .myFlexChild {
            width: 100%;
            display: flex;
    
            /* 
             * set this property if this is set to column by other css class 
             *  that is used by your target element 
             */
            flex-direction: row;
    
            /* 
             * necessary for our goal 
             */
            flex-wrap: wrap;
            height: 500px;
        }
    
        /* the element you want to put at the bottom */
        .myTargetElement {
            /*
             * will not work unless flex-wrap is set to wrap and 
             * flex-direction is set to row
             */
            align-self: flex-end;
        }
    

    HTML

        

    this is just sample

    set this to bottom

提交回复
热议问题