Center inline-block div in parent while ignoring floating elements

后端 未结 2 1157
小鲜肉
小鲜肉 2021-02-01 15:31

I am trying to center an inline div in its parent. The parent element also has a child div that floats to the right. Because of the right aligned

2条回答
  •  一生所求
    2021-02-01 15:54

    position:absolute is the only way

    DEMO http://jsfiddle.net/kevinPHPkevin/u4FWr/1/

    .center {
        display:inline-block;
        position: absolute;
        left:0;
        right:0;
    }
    

    EDITED

    not sure if this has already been suggested

    Or you can absolute: position; the right div instead

    DEMO http://jsfiddle.net/kevinPHPkevin/u4FWr/3/

    .right {
        display:inline-block;
        position: absolute;
        right:0;
    }
    

提交回复
热议问题