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

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

When doing something like this:

Left Div
Right Div
8条回答
  •  难免孤独
    2020-12-24 10:54

    No need to add extra elements. While flexbox uses very non-intuitive property names if you know what it can do you'll find yourself using it quite often.

    Item Left Item Right

    Plan on needing this often?

    .align_between {display: flex; justify-content: space-between;}
    

    I see other people using secondary words in the primary position which makes a mess of information hierarchy. If align is the primary task and right, left, and/or between are the secondary the class should be .align_outer, not .outer_align as it will make sense as you vertically scan your code:

    .align_between {}
    .align_left {}
    .align_outer {}
    .align_right {}
    

    Good habits over time will allow you to get to bed sooner than later.

提交回复
热议问题