填充父元素

时间:2019-01-14 16:36:56

标签: html css twitter-bootstrap

我正在尝试在右侧输入一个选择按钮。

我正在尝试使用引导程序,但似乎无法使选择内容填满input-group-addon。

有什么想法吗?

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>



<td class="form-group">
  <div class="col-xs-12 input-group">
    <div class="input-group-addon">
      <select>
        <option>+351</option>
      </select>
    </div>
    <input class="form-control">
  </div>
</td>

1 个答案:

答案 0 :(得分:0)

在这种情况下,Bootstrap没有直接支持,但是有解决此问题的方法。只需在表单元素之间插入一个空的.input-group-addon元素,例如:

<span class="input-group-addon" style="width:0px; padding-left:0px; padding-right:0px; border:none;"></span>

这是一个有效的示例:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<div class="input-group">
  <select class="form-control input-group-addon">
    <option>+351</option>
  </select>
  <span class="input-group-addon" style="width:0px; padding-left:0px; padding-right:0px; border:none;"></span>
  <input class="form-control">
</div>