Bootstrap 3 input 100%
时间: 2023-08-15 08:14:58 浏览: 40
想要使 Bootstrap 3 中的输入框(input)宽度占据父容器的 100%,可以使用如下样式:
```css
input[type="text"],
input[type="email"],
input[type="password"] {
width: 100%;
}
```
或者使用内置的 Bootstrap 样式类 `.form-control`:
```html
<input type="text" class="form-control" placeholder="输入框">
```
这样输入框的宽度就会自动填充整个容器。
相关问题
Bootstrap 3 label 高度100%
在 Bootstrap 3 中,要使 label 的高度占据父容器的 100%,可以使用如下样式:
```css
label {
display: inline-block;
height: 100%;
vertical-align: middle;
}
```
这样 label 元素的高度就会自适应其父容器的高度,并且在垂直方向上居中对齐。
如果要同时让 label 文本也垂直居中,可以将上述样式稍作修改:
```css
label {
display: inline-block;
height: 100%;
vertical-align: middle;
line-height: normal; /* 重置行高 */
}
label span {
display: inline-block;
vertical-align: middle;
}
```
然后在 HTML 中这样使用:
```html
<div class="form-group">
<label class="control-label col-md-2">
<span>标签</span>
</label>
<div class="col-md-10">
<input type="text" class="form-control">
</div>
</div>
```
这样就可以实现 label 文本和输入框都垂直居中的效果。
bootstrap 3 禁用input元素
要禁用一个input元素,可以在其上设置disabled属性。例如,以下代码可以禁用一个文本输入框:
```
<input type="text" name="myInput" value="Some text" disabled>
```
如果您使用的是Bootstrap 3,您可以使用以下代码来禁用一个input元素,并添加样式以反映其禁用状态:
```
<div class="form-group">
<label for="myInput">My Input:</label>
<input type="text" class="form-control" id="myInput" name="myInput" value="Some text" disabled>
</div>
```
在上面的代码中,我们使用了Bootstrap的.form-control类来设置输入框的样式,并将其包含在.form-group div中以获得正确的布局。通过设置disabled属性,输入框将被禁用,并且会显示为灰色,以反映其禁用状态。