【问题标题】:Alternatives for select element in BootstrapBootstrap 中选择元素的替代方案
【发布时间】:2015-06-28 14:52:28
【问题描述】:

我尝试使用引导程序创建带有选择元素的内联标签,

http://jsfiddle.net/kokilajs/1q53pr6j/

<form id="searchForm"  method="get" class="form-horizontal" role="form">
<div class="form-group">
    <label for="GPA" class="col-xs-2 control-label">GPA :</label>
    <div class="col-xs-2">
        <input name="GPA" type="number" value="2.5" class="form-control"                 id="GPA"/>
    </div>

    <div class="col-xs-8">
        <label for="faculty" class="control-label">Faculty:</label>
        <select class="form-control" name="faculty">
            <option>1</option>
            <option>2</option>
            <option>3</option>
            <option>4</option>
            <option>5</option>
        </select>
    </div>
</div>
</form>

我失败了! :( 然后我搜索发现 this

避免在此处使用 &lt;select&gt; 元素,因为它们无法在 WebKit 浏览器中完全设置样式。

有什么替代方法?他们没有在那里提到.. 有没有好的方法可以做到这一点而不需要大量的黑客攻击?

更新:避免使用&lt;select&gt; 元素

在引导页面他们 noted,我需要知道是否存在跨浏览器兼容性问题或什么?与选择元素?如果是选择元素的替代品是什么?

【问题讨论】:

  • yeh thnkz 没关系,另一件事是我需要澄清一下避免使用
  • 这是什么意思,在您需要自定义选择框的意义上选择替代品?
  • 他们提到here 避免在此处使用

标签: jquery html css twitter-bootstrap


【解决方案1】:

您所引用的页面仅用于使用Input groups 而不是用于内联表单。所以您可以这样使用:Demo

HTML:

<div class="col-xs-8">
        <div class="col-xs-4">  <label for="faculty" class="control-label">Faculty:</label></div>
         <div class="col-xs-8">
        <select class="form-control" name="faculty">
            <option>1</option>
            <option>2</option>
            <option>3</option>
            <option>4</option>
            <option>5</option>
             </select></div>
    </div>
</div>

要了解有关内联表单的更多信息,请参阅此Link

【讨论】:

    【解决方案2】:

    为选择元素试试这个 CSS。

    .selectClassName {
        max-width: 90%;
        display: inline;
    }
    

    【讨论】:

      【解决方案3】:

      您可以在表单标签上使用form-inline 类:

      <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
      <form id="searchForm"  method="get" class="form-inline" role="form">
       <div class="form-group">
           <label for="GPA" class="control-label">GPA :</label>
           <input name="GPA" type="number" value="2.5" class="form-control"                    id="GPA"/>
       </div> 
       <div class="form-group">
              <label for="faculty" class="control-label">Faculty:</label>
              <select class="form-control" name="faculty">
                  <option>1</option>
                  <option>2</option>
                  <option>3</option>
                  <option>4</option>
                  <option>5</option>
              </select>
        </div>
       </form>

      【讨论】:

        【解决方案4】:

        使用引导程序的内联文本框 就像你想要的那样

        <form id="searchForm"  method="get" class="form-horizontal" role="form">
        <div class="input-group">
            <span class="input-group-addon">GPA</span>
        
            <input type="text" class="form-control" aria-label="Amount (to the nearest dollar)">
            </div>
        
        </form>
        

        DEMO

        【讨论】:

          【解决方案5】:

          试试这个:

          DEMO1 // 您需要的移动视图

          DEMO2 // 实际移动端视图

          希望这对你有用..

           <div class="row">
                      <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
                          <label for="GPA" class="control-label">GPA :</label>
                      </div>
                      <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
                          <input name="GPA" type="number" value="2.5" class="form-control" id="GPA" />
                      </div>
                      <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
                          <label for="faculty" class="control-label">Faculty:</label>
                      </div>
                      <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
                          <select class="form-control" name="faculty">
                              <option>1</option>
                              <option>2</option>
                              <option>3</option>
                              <option>4</option>
                              <option>5</option>
                          </select>
                      </div>
                  </div>
          

          【讨论】:

            【解决方案6】:

            您可以使用引导程序中的内联形式结构:
            http://getbootstrap.com/css/#forms-inline

            删除所有类,如“col-xs”,并将标签/字段包装在&lt;div class="form-group"&gt;
            您必须为输入和选择字段指定宽度。

            input, select {
                width: 200px !important;
            }
            

            可能需要自定义宽度
            输入和选择的宽度:100%;应用 默认情况下在 Bootstrap 中。在内联表单中,我们将其重置为宽度: 汽车;因此多个控件可以驻留在同一行。根据 您的布局,可能需要额外的自定义宽度。

            您可以在此处查看演示:
            http://jsfiddle.net/1q53pr6j/3/

            【讨论】:

              猜你喜欢
              • 2015-03-20
              • 2011-07-23
              • 1970-01-01
              • 1970-01-01
              • 2021-11-17
              • 2016-07-28
              • 2014-02-02
              • 1970-01-01
              • 2014-04-11
              相关资源
              最近更新 更多