Flexbox: flex-start, self-start, and start; What's the difference?

后端 未结 2 1432
逝去的感伤
逝去的感伤 2021-02-02 09:19

I just noticed some values of the align-self property that I haven\'t seen before. What are start, end, self-start, and

相关标签:
2条回答
  • 2021-02-02 09:28

    The values flex-end and flex-start (among others) were created for use with flex layout.

    However, the W3C has been developing the Box Alignment Module, which establishes a common set of alignment properties and values for use across multiple box models, including flex, grid, table and block.

    So what you're seeing are the newer values that will eventually replace the existing layout-specific values.

    Here's how it's described in the flexbox specification:

    § 1.2. Module interactions

    The CSS Box Alignment Module extends and supercedes the definitions of the alignment properties (justify-content, align-items, align-self, align-content) introduced here.

    There's similar language in the Grid specification. Here's an example:

    § 10.1. Gutters: the row-gap, column-gap, and gap properties

    The row-gap and column-gap properties (and their gap shorthand), when specified on a grid container, define the gutters between grid rows and grid columns. Their syntax is defined in CSS Box Alignment 3 §8 Gaps Between Boxes.

    The original properties – grid-row-gap, grid-column-gap and grid-gap – didn't last long. Although, for the sake of backward compatibility, I'm sure they're still respected.

    0 讨论(0)
  • 2021-02-02 09:36

    flex-start takes into account the presence of the -reverse values of the flex direction, while start does not.

    For example, in a left-to-right writing mode with a flex container set to flex-direction:row-reverse, justify-content:start would cause all items to be justified to the left, while justify-content:flex-start would cause all items to be justified to the right.

    div {
      padding: 4px;
      border: 1px solid red
    }
    
    #div1 {
      display: flex;
      flex-direction: row-reverse;
      justify-content: start
    }
    
    #div2 {
      display: flex;
      flex-direction: row-reverse;
      justify-content: flex-start
    }
    <ul>
      <li><code>align-content: start</code>
        <div id=div1>
          <div>Flex 1</div>
          <div>Flex 2</div>
        </div>
      </li>
      <br>
      <li><code>align-content: flex-start</code>
        <div id=div2>
          <div>Flex 1</div>
          <div>Flex 2</div>
        </div>
      </li>
    </ul>

    Edit on Jul 15 2019

    The described different behaviour is true in Firefox browser (at least until 68), while in Chrome, as noted in comment by diachedelic, both properties work in the same way

    0 讨论(0)
提交回复
热议问题