How do I evenly add space between a label and the input field regardless of length of text?

后端 未结 5 1973
悲哀的现实
悲哀的现实 2021-02-01 04:13

Let\'s say I have 10 input fields and before the input fields on the left side I have span tag that holds the text to indicate what the user should enter into the field. I did

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-01 04:44

    This can be accomplished using the brand new CSS display: grid (browser support)

    HTML:

    CSS:

    .container {
      display: grid;
      grid-template-columns: 1fr 3fr;
    }
    

    When using css grid, by default elements are laid out column by column then row by row. The grid-template-columns rule creates two grid columns, one which takes up 1/4 of the total horizontal space and the other which takes up 3/4 of the horizontal space. This creates the desired effect.

    JS-FIDDLE

提交回复
热议问题