CSS Bootstrap 的 control-label 类有什么作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37248897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 11:56:29  来源:igfitidea点击:

What does Bootstrap's control-label class do?

cssformstwitter-bootstraplabel

提问by ira

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

Bootstrap 3 类将哪些 CSS 格式应用于<label>HTML 元素.control-label。(我也面临着使用 Chrome 的 devtools 定位该类的困难

Moreover, in the official Bootstrap 3 documentation, .control-labelseems to be used only in case of .form-horizontal. Is that true and why?

而且,在官方的 Bootstrap 3文档中.control-label似乎只在.form-horizontal. 这是真的吗?为什么?

回答by Ariful Haque

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.

control-label 类对于验证状态很有用,这就是为什么我们在所有标签中都需要它,即使引导程序的文档没有提到的字段。

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

我们可以在 bootstrap 源代码中看到它定义 has-success、has-warning 等类:https: //github.com/twbs/bootstrap/blob/bfb99413eefbbe2e8fbb1e477cbfa63ea7d36140/dist/css/bootstrap-rtl。 #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>

enter image description here

在此处输入图片说明

Using control-label class:

使用控制标签类:

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

enter image description here

在此处输入图片说明

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

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