Bulma 输入宽度不一致

Jua*_*gel 2 html css flexbox bulma

在此输入图像描述我有一个使用 Bulma 框架的简单表单。我的输入宽度不一致并且找不到补救措施。https://jsfiddle.net/onzpum90/当标签很长时似乎会发生这种情况。如果我保留短标签,问题就消失了。为什么标签会影响输入宽度?可能是我不熟悉的flexbox问题。有人知道解决方案吗?

<form action="">
<div class="field">
<div class="field-body">
  <div class="field">
    <p class="control is-expanded">
      <label class="label">A very long label for a form</label> 
      <input type="text" name="" value="" class="input ">
     </p>
  </div> 
  <div class="field is-grouped">
    <p class="control is-expanded">
      <label class="label">Email</label>
      <input type="email" name="email" value="" class="input ">
    </p>
  </div>
  </div>
 </div>
 <div class="field is-horizontal">
<div class="field-body">
  <div class="field">
    <p class="control is-expanded">
      <label class="label">Short Label</label> 
      <input type="text" name="" value="" class="input ">
     </p>
  </div> 
  <div class="field is-grouped">
    <p class="control is-expanded">
      <label class="label">Email</label>
      <input type="email" name="email" value="" class="input ">
    </p>
   </div>
  </div>
 </div>
</form>
Run Code Online (Sandbox Code Playgroud)

Mic*_*l_B 5

表单元素 ( .field) 的 div 容器是大小为 的 Flex 项目flex-grow: 1

@media screen and (min-width: 769px), print
.field-body > .field:not(.is-narrow) {
    -webkit-box-flex: 1;
    flex-grow: 1;
}
Run Code Online (Sandbox Code Playgroud)

虽然你已经定义了flex-grow,但你还没有定义flex-basis。因此,flex-basis保留其默认设置:auto

使用 时,容器空间会根据项目内容的长度按比例flex-basis: auto分配。

因此,标签较长的物品长度也会较长。

您只需设置为即可解决该flex-basis问题0

删除应用于的flex-grow和规则并使用它:flex-shrink.field

flex: 1 1 0
Run Code Online (Sandbox Code Playgroud)

与以下内容相同:

flex: 1
Run Code Online (Sandbox Code Playgroud)

修改后的演示

flex-basis: auto有关vs之间差异的完整说明flex-basis: 0,请参阅这篇文章:Make flex-grow Expand items based on their original size