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

前端 未结 6 536
慢半拍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 16:01

    Set a minimum width which is the width of the typical widest label. Then use JavaScript to cope for edge cases. If the user doesn't have JavaScript, you can fallback to an 'OK' design.

    Get the widest label in the form using the function from this answer, and then set the widths of all labels to that value.

    This is a very similar setup to this answer although that one is setting

  • s instead of s.

提交回复
热议问题