简体   繁体   English

引导表单控件类有什么用?

[英]What is the bootstrap form-control class for?

I'm having trouble wrapping my brain around the strategy for how to use the form-control class offered by Bootstrap. 我在围绕如何使用Bootstrap提供的form-control类的策略时遇到了麻烦。

On one hand I have this rather bland comment from the Bootstrap documentation: 一方面,我从Bootstrap文档中得到了一个相当平淡的评论:

Textual form controls—like inputs, selects, and textareas—are styled with the .form-control class. 文本表单控件(如输入,选择和文本区域)使用.form-control类设置样式。 Included are styles for general appearance, focus state, sizing, and more. 其中包括用于一般外观,焦点状态,大小调整等的样式。

Ref: https://getbootstrap.com/docs/4.0/components/forms/#form-controls 参考: https : //getbootstrap.com/docs/4.0/components/forms/#form-controls

While on the other hand I have rather in-the-weeds code to look at: 另一方面,我要查看杂草中的代码:

.form-control {
  display: block;
  width: 100%;
  height: $input-height;
  padding: $input-padding-y $input-padding-x;
  // ... 40-some lines elided ...
}

ref: https://github.com/twbs/bootstrap/blob/275cd7f91eed9f4051d85c295e5c14ef08937804/scss/_forms.scss 参考: https : //github.com/twbs/bootstrap/blob/275cd7f91eed9f4051d85c295e5c14ef08937804/scss/_forms.scss

My question: How can I holistically approach modifying existing code or writing new code with form-control . 我的问题:如何使用form-control整体地修改现有代码或编写新代码。

You add that class to text input elements (input, select, textarea), eg <input type="email" class="form-control" value="" placeholder="Your email address" /> This is Bootstrap's way of forcing form elements to look the same. 您将该类添加到文本输入元素(输入,选择,文本区域)中,例如<input type="email" class="form-control" value="" placeholder="Your email address" />这是Bootstrap的强制方式表单元素看起来相同。

The CSS is so long because they're accounting for all the differences in how browsers natively render those elements. CSS之所以这么长,是因为它们考虑了浏览器本地呈现这些元素的方式的所有差异。

Bootstrap form-control class is use to make an element fit it container Bootstrap Form-Control类用于使元素适合容器

<div>
<input type='text' class='form-control'>
</div>



div{
width: 400px; 
background: gray;
}

Define a .form-control class again. 再次定义一个.form-control类。 It will override properties in existing .form-control of Bootstrap. 它将覆盖Bootstrap的现有.form-control的属性。

 <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> <style> .form-control { border-radius: unset; } </style> <input class="form-control" type="text" value="Test"> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Bootstrap 3表单控件不堆叠 - Bootstrap 3 form-control not stacking Bootstrap-如何添加 <select class=“form-control”>动态地在JavaScript中? - Bootstrap - How to add <select class=“form-control”> dynamically in JavaScript? 如何删除表单控件 class 中的引导程序轮廓? - How to remove bootstrap's outline in form-control class? Bootstrap - 带有“form-control”类的输入的默认 CSS 框阴影 - Bootstrap - Default CSS Box Shadow for Inputs with 'form-control' Class 引导程序3:绝对位置不适用于表单控件类 - bootstrap 3: position absolute not work with form-control class Bootstrap .form-control和RecurlyJS iframe - Bootstrap .form-control and RecurlyJS iframe Center Bootstrap表单控件到浏览器的中心 - Center Bootstrap form-control to center of browser 在选择选项上自定义引导表单控件 - customizing bootstrap form-control on select option 如何使用Twitter Bootstrap中的类form-control将具有btn类的按钮与具有表单输入元素的表单输入元素对齐 - How to align a button with class btn with form input element with class form-control from twitter bootstrap 如何使用Simple_Form gem将bootstrap&#39;form-control&#39;类添加到选择中? - How do I add a the bootstrap 'form-control' class to a select using the Simple_Form gem?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM