CSS, how to create a label width of the longest containing text?

前端 未结 6 485
慢半拍i
慢半拍i 2021-02-02 15:29

I have a table with two columns, like this:

Firstname: Jeff

Where the first column is a label and the second one is an input. Now I\'m setting

6条回答
  •  时光取名叫无心
    2021-02-02 15:53

    The easiest would be to select a fixed size large enough.

    If you really want to simulate the exact behavior of a table you have two choices:

    • use table
    • simulate table with CSS:

      .block { display: table; }
      .row   { display: table-row; }
      label { display: table-cell; }
      

    With the following HTML:

    ...
    ...

    I don't think there exists another way of dealing with this. If you really don't want to change your HTML, your only hope might be to use javascript.

提交回复
热议问题