Bootstrap使用select作为输入附加组件

时间:2016-03-12 05:54:00

标签: html css twitter-bootstrap twitter-bootstrap-3

我正在尝试用input-group-addon输入替换select,但这会给我定位问题。我可以单击下拉列表并选择选项,但宽度都是错误的。我会在下面张贴一张图片。

我希望select位于输入旁边,因为用户可以输入mm或in中的大小。

enter image description here

我的代码如下:

<div class="form-group">
    <label for="wrapped">Wrapped Around</label>
    <div class="input-group">
        <input type="number" class="form-control" id="wrapped" placeholder="Wrapped Around" name="wrapped" step="0.01">
        <div class="input-group-addon">
            <select class="form-control">
                <option selected>Pick</option>
                <option>mm</option>
                <option>in</option>
            </select>
        </div>
    </div>
</div>

任何帮助都会很棒,谢谢!

1 个答案:

答案 0 :(得分:5)

#wrapped+.input-group-addon {
    margin: 0;
    padding: 0;
    min-width: 8rem;
    border: none;
}
#wrapped+.input-group-addon>.form-control {
    border-radius: 0 .4rem .4rem 0;
    border-left: none;
}

/* CSS below is for centering the div in the page, you only need what is above this line */

body {
    min-height: 100vh;
}
body {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
        -ms-flex-pack: center;
            justify-content: center;
    -webkit-box-align: center;
    -webkit-align-items: center;
        -ms-flex-align: center;
            align-items: center;
}
body > .form-group {
    width: 50vw;
}
<link rel="stylesheet" 
      href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" 
      integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" 
      crossorigin="anonymous"
      />
<div class="form-group">
  <label for="wrapped">Wrapped Around</label>
  <div class="input-group">
    <input id="wrapped" 
           class="form-control" 
           type="number" 
           placeholder="Wrapped Around" 
           name="wrapped" 
           step="0.01"
           />
    <div class="input-group-addon">
      <select class="form-control">
        <option selected>Pick</option>
        <option>mm</option>
        <option>in</option>
      </select>
    </div>
  </div>
</div>
屏幕截图,根据评论:

enter image description here

有没有人遇到Joe在评论中提到的问题:border-radius没有在选择的左侧重置?