入力グループに 2 つの入力を含めるにはどうすればよいですか?
<div class="input-group">
<input type="text" class="form-control" placeholder="MinVal">
<input type="text" class="form-control" placeholder="MaxVal">
</div>
これは機能しません。インラインではなく水平です
入力グループに 2 つの入力を含めるにはどうすればよいですか?
<div class="input-group">
<input type="text" class="form-control" placeholder="MinVal">
<input type="text" class="form-control" placeholder="MaxVal">
</div>
これは機能しません。インラインではなく水平です
回避策:
<div class="input-group">
<input type="text" class="form-control input-sm" value="test1" />
<span class="input-group-btn" style="width:0px;"></span>
<input type="text" class="form-control input-sm" value="test2" />
</div>
欠点: 2 つのテキスト フィールド間の境界線が崩れることはありませんが、隣り合ったままになります。
アップデート
スタリンコに感謝
この手法により、2 つ以上の入力を接着できます。ボーダーの折りたたみは、 "margin-left: -1px"
( -2px
3 番目の入力など) を使用して実現されます。
<div class="input-group">
<input type="text" class="form-control input-sm" value="test1" />
<span class="input-group-btn" style="width:0px;"></span>
<input type="text" class="form-control input-sm" value="test2" style="margin-left:-1px" />
<span class="input-group-btn" style="width:0px;"></span>
<input type="text" class="form-control input-sm" value="test2" style="margin-left:-2px" />
</div>
それらを隣り合わせにしたい場合:
<form action="" class="form-inline">
<div class="form-group">
<input type="text" class="form-control" placeholder="MinVal">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="MaxVal">
</div>
</form>
更新番号 1:.input-group
この例で使用する場合:
<form action="" class="form-inline">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon">@</span>
<input type="text" class="form-control" placeholder="Username">
</div>
</div>
<div class="form-group">
<div class="input-group">
<input type="text" class="form-control">
<span class="input-group-addon">.00</span>
</div>
</div>
</form>
クラス.input-group
は、ボタンなどで入力を拡張するためにあります(直接接続されています)。チェックボックスやラジオボタンも可能です。ただし、2 つの入力フィールドでは機能しないと思います。
更新番号 2:.form-horizontal
タグを使用すると、.form-group
基本的にタグになるため.row
、次のような列クラスを使用できます.col-sm-8
。
<form action="" class="form-horizontal">
<div class="form-group">
<div class="col-sm-8">
<input type="text" class="form-control" placeholder="MinVal">
</div>
<div class="col-sm-4">
<input type="text" class="form-control" placeholder="MaxVal">
</div>
</div>
</form>
「form-inline 」クラスを使用せずに複数の入力をインラインで表示するには、次のコードを使用できます。
<div class="input-group">
<input type="text" class="form-control" value="First input" />
<span class="input-group-btn"></span>
<input type="text" class="form-control" value="Second input" />
</div>
次に、CSS セレクターを使用します。
/* To remove space between text inputs */
.input-group > .input-group-btn:empty {
width: 0px;
}
基本的に、 inputタグの間に「 input-group-btn」クラスの空のspanタグを挿入する必要があります。
入力グループとブートストラップ選択グループの例をもっと見たい場合は、次の URL を見てください: http://jsfiddle.net/vkhusnulina/gze0Lcm0
<select>
HTML要素で選択できる「タイトル」フィールドをその中に含めたい場合は、それも可能です
コードスニペット
<div class="form-group">
<div class="input-group input-group-lg">
<div class="input-group-addon">
<select>
<option>Mr.</option>
<option>Mrs.</option>
<option>Dr</option>
</select>
</div>
<div class="input-group-addon">
<span class="fa fa-user"></span>
</div>
<input type="text" class="form-control" placeholder="Name...">
</div>
</div>
このページのどの回答にも満足できなかったので、自分で少しいじりました。私は次のことを思いついた
angular.module('showcase', []).controller('Ctrl', function() {
var vm = this;
vm.focusParent = function(event) {
angular.element(event.target).parent().addClass('focus');
};
vm.blurParent = function(event) {
angular.element(event.target).parent().removeClass('focus');
};
});
.input-merge .col-xs-2,
.input-merge .col-xs-4,
.input-merge .col-xs-6 {
padding-left: 0;
padding-right: 0;
}
.input-merge div:first-child .form-control {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}
.input-merge div:last-child .form-control {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
.input-merge div:not(:first-child) {
margin-left: -1px;
}
.input-merge div:not(:first-child):not(:last-child) .form-control {
border-radius: 0;
}
.focus {
z-index: 2;
}
<html ng-app="showcase">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body class="container">
<label class="control-label">Person</label>
<div class="input-merge" ng-controller="Ctrl as showCase">
<div class="col-xs-4">
<input class="form-control input-sm" name="initials" type="text" id="initials"
ng-focus="showCase.focusParent($event)" ng-blur="showCase.blurParent($event)"
ng-model="person.initials" placeholder="Initials" />
</div>
<div class="col-xs-2">
<input class="form-control input-sm" name="prefixes" type="text" id="prefixes"
ng-focus="showCase.focusParent($event)" ng-blur="showCase.blurParent($event)"
ng-model="persoon.prefixes" placeholder="Prefixes" />
</div>
<div class="col-xs-6">
<input class="form-control input-sm" name="surname" type="text" id="surname"
ng-focus="showCase.focusParent($event)" ng-blur="showCase.blurParent($event)"
ng-model="persoon.surname" placeholder="Surname" />
</div>
</div>
</body>
</html>
これにより、個々の入力の幅を好みに合わせて設定できます。また、上記のスニペットのマイナーな問題は、入力がフォーカスされている場合や有効でない場合に不完全に見えることです。私はこれを角度のあるコードで修正しましたが、jQuery やネイティブの JavaScript などを使ってこれを簡単に行うことができます。
このコードは、含まれている div にクラス .focus を追加するため、入力がフォーカスされたときに他のものよりも高い z-index を取得できます。