【问题标题】:How to allow a group of labels to grow together and to respectively shrink the input fields?如何让一组标签一起增长并分别缩小输入字段?
【发布时间】:2016-11-08 02:18:36
【问题描述】:

我希望有一组标签占用与最宽标签一样多的水平空间,同时所有输入字段都应缩小以适应更大的标签。我需要这个,因为我处理翻译并且不确定某个标签的宽度。

类似这样的:

form {
  display: table;
  width: 100%;
}

label {
  width: 1%;
  display: table-cell;
  white-space: nowrap;
  padding-right: 1em;
}

input {
  display: inline-block;
  width: 100%;
}

.input-group {
  display: table-row;
}

* {
  line-height: 2em;
}

body {
  padding: 2em;
}
<form>
  <div class="input-group">
    <label for="name">Full name of your family and yourself</label>
    <input type="text" id="name" name="name" placeholder="optional">
  </div>
   <div class="input-group">
    <label for="email">Email</label>
    <input type="text" id="email" name="email" placeholder="optional">
  </div>
    <div class="input-group">
    <label for="phone">Phone</label>
    <input type="text" id="phone" name="phone" placeholder="optional">
  </div>
</form>

你也可以在 Codepen 中查看:

http://codepen.io/aboutandre/pen/bZRjqB

但是有没有更优雅的方式来做到这一点,更通用并且不涉及使用表格(如 HTML 或 CSS)?

【问题讨论】:

    标签: html css forms label input-field


    【解决方案1】:

    如何指定输入字段的宽度以从所需/确定的输入字段继承? 因此,例如,如果名称字段是行列式,则使其宽度为 100%,并且其他两个元素 - 宽度:继承;

    【讨论】:

    • 我没有完全听从你的回答。你能举个例子吗?
    猜你喜欢
    • 2020-10-05
    • 1970-01-01
    • 1970-01-01
    • 2020-03-14
    • 2011-10-14
    • 1970-01-01
    • 1970-01-01
    • 2021-11-25
    • 1970-01-01
    相关资源
    最近更新 更多