bootstrap的控件标签类有什么作用?

时间:2022-11-23 17:32:48

What CSS formatting is applied to the <label> html element by the .control-label bs3 class. (I also face difficulties locating that class using chrome's devtools)

.control-label bs3类对

Moreover, in the official BS3 documentation, .control-label seems to be used only in case of .form-horizontal. Is that true and why ?

此外,在官方BS3文档中,.control-label似乎仅在.form-horizo​​ntal的情况下使用。这是真的吗?为什么?

1 个解决方案

#1


27  

The control-label class is useful for validation states, that's why we need it in all labels even the fields bootstrap's documentation doesn't mention.

控制标签类对于验证状态非常有用,这就是为什么我们在所有标签中都需要它,即使字段bootstrap的文档没有提到。

We can see it in the bootstrap source code when it is defining the has-success, has-warning, etc classes: https://github.com/twbs/bootstrap/blob/bfb99413eefbbe2e8fbb1e477cbfa63ea7d36140/dist/css/bootstrap-rtl.css#L3242

当我们定义has-success,has-warning等类时,我们可以在bootstrap源代码中看到它:https://github.com/twbs/bootstrap/blob/bfb99413eefbbe2e8fbb1e477cbfa63ea7d36140/dist/css/bootstrap-rtl.css #L3242

As you can see, it uses the control-label class not the label element. If we remove the control-label we'll have an undesired effect of not coloring the label green.

如您所见,它使用control-label类而不是label元素。如果我们删除控制标签,我们将会产生一种不会使标签变绿的不良影响。

Vertical form without control-label class and has-success on form-group:

没有控件标签类的垂直表单,并且在表单组中具有成功性:

<div class="form-group has-success">
    <label for="exampleInputEmail1">Email address</label>
    <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email">
  </div>

bootstrap的控件标签类有什么作用?

Using control-label class:

使用control-label类:

<label for="exampleInputEmail1" class='control-label'>Email address</label>

bootstrap的控件标签类有什么作用?

That's why I think it is better to keep it! Unless no color is the desired effect.

这就是为什么我认为保留它更好!除非没有颜色是理想的效果。

#1


27  

The control-label class is useful for validation states, that's why we need it in all labels even the fields bootstrap's documentation doesn't mention.

控制标签类对于验证状态非常有用,这就是为什么我们在所有标签中都需要它,即使字段bootstrap的文档没有提到。

We can see it in the bootstrap source code when it is defining the has-success, has-warning, etc classes: https://github.com/twbs/bootstrap/blob/bfb99413eefbbe2e8fbb1e477cbfa63ea7d36140/dist/css/bootstrap-rtl.css#L3242

当我们定义has-success,has-warning等类时,我们可以在bootstrap源代码中看到它:https://github.com/twbs/bootstrap/blob/bfb99413eefbbe2e8fbb1e477cbfa63ea7d36140/dist/css/bootstrap-rtl.css #L3242

As you can see, it uses the control-label class not the label element. If we remove the control-label we'll have an undesired effect of not coloring the label green.

如您所见,它使用control-label类而不是label元素。如果我们删除控制标签,我们将会产生一种不会使标签变绿的不良影响。

Vertical form without control-label class and has-success on form-group:

没有控件标签类的垂直表单,并且在表单组中具有成功性:

<div class="form-group has-success">
    <label for="exampleInputEmail1">Email address</label>
    <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email">
  </div>

bootstrap的控件标签类有什么作用?

Using control-label class:

使用control-label类:

<label for="exampleInputEmail1" class='control-label'>Email address</label>

bootstrap的控件标签类有什么作用?

That's why I think it is better to keep it! Unless no color is the desired effect.

这就是为什么我认为保留它更好!除非没有颜色是理想的效果。