【问题标题】:Bootstrap 3: does form-horizontal work for radio buttons with a control-label?Bootstrap 3:form-horizo​​ntal 是否适用于带有控制标签的单选按钮?
【发布时间】:2015-12-09 01:41:24
【问题描述】:

这浪费了我一天的好几个小时。这是一个非常简单的表单,在bootply 上有两个单选按钮和一个标签。这在 2.3.2 上按预期工作:左侧的“日期范围”,右侧的按钮。在 Bootstrap 3 上,一切都出来了,它基本上是垂直的而不是水平的,文本是粗体的,只是一团糟。有什么想法,除了重新做一个网格吗?

谢谢。

编辑

这是预期的布局,当在 bootply 上选择 B2.3.2 时:

这是我选择任何 B3+ 时得到的结果:

【问题讨论】:

  • 我发布了您应该使用的课程。表单进行了很多更改,迁移列表很有帮助,但没有什么比在 getbootstrap.com 上拆开示例更有帮助
  • 谢谢 - 我认为您的意思是,提供对齐的旧类已被删除,您必须使用网格布局手动对齐所有内容?我几天前才开始使用 Bootstrap,这在文档中并不明显。
  • 在下面的示例中,只有网格类设置了控件标签和具有第二个右列的容器。您可以为收音机和内联复选框使用“radio-inline”类。
  • col-sm- 肯定不是正确的做法。我不想要响应式布局 - 我想要一个 fixed 布局,即。如果您转到 bootply 示例,登录并从 B3 更改为 B2.3.2,您将获得的布局。换句话说,左侧有一个标签,标签右侧有两个堆叠的单选按钮,一个单选按钮位于另一个单选按钮的顶部。 B3 正确堆叠了 2 个收音机(一个顶部,一个底部),但将标签留在顶部,而不是左侧,并搞砸了字体样式。谁能说服我网格化是答案,或者修复 B3 代码?
  • 您可以使用 col-xs,然后使用正确的类将它们堆叠在里面。请参见下面的示例。我已经在 BS3 上使用表单 3 个月了,这是正确的做法,因为所有表单元素都是 100%,所以你需要 col- 但你可以使用 xs 品种并获得一个固定的布局,而不是从断点切换到断点

标签: twitter-bootstrap twitter-bootstrap-3


【解决方案1】:

我需要相同的布置,但同时使用水平和垂直收音机。对于 Bootstrap 3.2,有一个 form-horizo​​ntal 可以很好地与列一起使用。

<form class="form-horizontal" role="form">

完整表格

<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
  <p class="bg-warning">Note: In the Stack Snippet, you may need to click "Full Page", otherwise the container is narrow enough to cause Bootstrap to stack the labels over the fields.</p>
    <form class="form-horizontal" role="form">

    <div class="form-group">
        <label class="col-sm-4 control-label">Season</label>
        <div class="col-sm-8">
            <label class="radio-inline"> <input type="radio" name="season" id="seasonSummer" value="summer" checked> Summer </label>
            <label class="radio-inline"> <input type="radio" name="season" id="seasonWinter" value="winter"> Winter </label>
            <label class="radio-inline"> <input type="radio" name="season" id="seasonSpringFall" value="spring-fall" disabled> Spring-Fall </label>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-4 control-label">Clouds</label>
        <div class="col-sm-8">
            <label class="radio-inline"> <input type="radio" name="clouds" id="Clear" value="clear" checked> Clear </label>
            <label class="radio-inline"> <input type="radio" name="clouds" id="Cloudy" value="cloudy"> Cloudy </label>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-4 control-label">Load Forecast</label>
        <div class="col-sm-8">
            <div class="radio">
                <label> <input type="radio" name="load" id="WeekdayAverage" value="weekdayaverage" checked> Weekday - Average </label>
            </div>
            <div class="radio">
                <label> <input type="radio" name="load" id="WeekdayPeak" value="weekdaypeak"> Weekday - Peak </label>
            </div>
            <div class="radio">
                <label> <input type="radio" name="load" id="Weekend" value="weekend" disabled> Weekend </label>
            </div>
        </div>
    </div>

    </form>
</div>

【讨论】:

    【解决方案2】:

    要做你想做的事,你必须使用 col-* 类,因为所有表单元素都是 100% 宽度,所以你必须有一个 col-* 来固定你想要的宽度。您可以使用 col-xs-*,它适用于所有尺寸,不响应:

    示例:http://bootply.com/102912

    <form class="form-horizontal">
     <fieldset>
      <div class="form-group">
       <label class="col-xs-3 control-label">Date Range</label>
       <div class="col-xs-9">
        <div class="radio">
         <label>
          <input id="inlineradio1" name="sampleinlineradio" value="option1" type="radio">
          Radio 0</label>
        </div>
        <div class="radio">
         <label>
          <input id="inlineradio1" name="sampleinlineradio" value="option1" type="radio">
          Radio 0</label>
        </div>
        <div class="radio">
         <label>
          <input id="inlineradio1" name="sampleinlineradio" value="option1" type="radio">
          Radio 0</label>
        </div>
       </div>
      </div>
     </fieldset>
    </form>
    

    如果您希望在同一行中不使用列类的单选框、复选框或其他表单元素,则表单的类为.form-inline

    http://bootply.com/102908

    <form class="form-inline">
       <div class="form-group">
        <label class="radio-inline">Date Range</label>
             <label class="radio-inline">
         <input id="inlineradio1" name="sampleinlineradio" value="option1" type="radio">
         Radio 0</label>
        <label class="radio-inline">
         <input id="inlineradio2" name="sampleinlineradio" value="option2" type="radio">
         Radio 2</label>
        <label class="radio-inline">
         <input id="inlineradio3" name="sampleinlineradio" value="option3" type="radio">
         Radio 3</label>
        </div>
       <!--form-group-->
     </form>
    

    【讨论】:

    • 好的,你已经说服了我,但我不禁想到,简单地使用表格会更容易,更合乎逻辑。
    猜你喜欢
    • 1970-01-01
    • 2012-11-10
    • 2012-11-15
    • 1970-01-01
    • 2014-06-28
    • 2013-10-09
    • 1970-01-01
    • 2014-11-11
    • 1970-01-01
    相关资源
    最近更新 更多