Is such alignment achievable without ?
后端 未结 5 1107
攒了一身酷
攒了一身酷 2021-01-17 11:57

\"The

My goal is an alignment as shown in the attached image (the fields on the left may have a

5条回答
  •  南笙
    南笙 (楼主)
    2021-01-17 12:37

    I found a much easier way to do this by accident. Say you have the following:

    Something else
    Some text 1
    Some text 2
    Some text 3
    Some text 4

    You can align Some text 1 and Some text 2 using css table display styling like this:

    .a {
      display: table-row;
    }
    .a div {
      display: table-cell;
    }
    

    The coolest thing is that as long as the 'top' div is NOT styled display: table, then other things like "Something else" can be ignored in terms of alignment. If the 'top' div IS styled display: table, then "Some text 1" will be aligned with "Something else" (ie it treats all its children like table rows, even if they have a different display style).

    This works in Chrome, not sure if its supposed to behave this way, but I'm glad it works.

      .a {
          display: table-row;
        }
        .a div {
          display: table-cell;
        }
       
    Something else
    Some text 1
    Some text 2
    Some text 3
    Some text 4

提交回复
热议问题