使用Bootstrap的多行输入表单字段

Bri*_*ian 35 html html5 twitter-bootstrap

<form class="span6">
  <h2>Get In Touch</h2><br>
  <input class="span6" type="text" placeholder="Your first name" required>
  <input class="span6" type="text" placeholder="Your last name" required>
  <input class="span6" type="email" placeholder="Your email" required>
  <input class="span6" type="text" placeholder="Your phone number">
  <input class="span6" type="text" rows="3" placeholder="What's up?" required><br>
  <button type="submit" class="btn btn-primary">Submit</button>
  <button type="clear" class="btn">Clear</button>
</form><!--/.span6-->
Run Code Online (Sandbox Code Playgroud)

这是我在Bootstrap中使用的表单.我正在尝试使我的最后一个输入字段跨越6列,向下3行,但它只显示为6列和1行.关于如何使我的输入框更大的任何想法?谢谢.

Nic*_*son 54

我认为问题是你使用的是type ="text"而不是textarea.你想要的是:

<textarea class="span6" rows="3" placeholder="What's up?" required></textarea>
Run Code Online (Sandbox Code Playgroud)

为了澄清,type ="text"将始终是一行,其中textarea可以是多行.

  • Touché,@ nick-mithinson.我想我会留下我的评论,因为人们可能会在使用`input-group`s时提出这个问题.谢谢你的纠正! (6认同)
  • 根据[bootstrap的文档](http://getbootstrap.com/components/#textual- <input> s-only),这可能不是最好的主意:"避免在这里使用`<textarea>`元素作为`row`在某些情况下,不会尊重s属性." (4认同)
  • 你提供的那个链接说要避免输入组中的textarea元素,这不是 (3认同)

tre*_*eat 37

Nick Mitchinson的答案是Bootstrap第2版.

如果您使用的是Bootstrap版本3,那么表单已经发生了一些变化.对于bootstrap 3,请使用以下代码:

<div class="form-horizontal">
    <div class="form-group">
        <div class="col-md-6">
            <textarea class="form-control" rows="3" placeholder="What's up?" required></textarea>
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

其中,col-md-6将针对中型设备.您可以添加col-xs-6等来定位较小的设备.