How do you align left / right a div without using float?

后端 未结 8 750
猫巷女王i
猫巷女王i 2020-12-24 10:04

When doing something like this:

Left Div
Right Div
8条回答
  •  时光取名叫无心
    2020-12-24 10:56

    you could use things like display: inline-block but I think you would need to set up another div to move it over, if there is nothing going to the left of the button you could use margins to move it into place.

    Alternatively but not a good solution, you could position tags; put the encompassing div as position: relative and then the div of the button as position: absolute; right: 0, but like I said this is probably not the best solution

    HTML

    Left Div
    Right Div

    CSS

    .parent {
      position: relative;
    }
    .right {
        position: absolute;
        right: 0;
    }
    

提交回复
热议问题