我正在尝试将我的应用程序从 Bootstrap 4 更新到 Bootstrap 5,但是所有使用表单类的元素,例如 form-group
, form-row
, form-inline
完全破碎。
原文由 Francesco Borzi 发布,翻译遵循 CC BY-SA 4.0 许可协议
我正在尝试将我的应用程序从 Bootstrap 4 更新到 Bootstrap 5,但是所有使用表单类的元素,例如 form-group
, form-row
, form-inline
完全破碎。
原文由 Francesco Borzi 发布,翻译遵循 CC BY-SA 4.0 许可协议
.inline-form
迁移到 Bootstrap 5+inline-form
类替换为 flexbox 辅助类: d-flex flex-row align-items-center flex-wrap
。mr-*
类来分隔表单元素,请将它们替换为等效的 me-*
类(“margin end”)。例如 mr-2
变成 me-2
。同样, ml-*
变为 ms-*
(“保证金开始”)。custom-select
变为 v5 中的 form-select
。将下面的 Bootstrap 4 内联形式与 Bootstrap 5 中的完全等效形式进行比较。
这是引导程序 4 代码。
<form class="form-inline">
<label class="my-1 mr-2" for="inlineFormCustomSelectPref">Preference</label>
<select class="custom-select my-1 mr-sm-2" id="inlineFormCustomSelectPref">
<option selected>Choose...</option>
</select>
<div class="custom-control custom-checkbox my-1 mr-sm-2">
<input type="checkbox" class="custom-control-input" id="customControlInline">
<label class="custom-control-label" for="customControlInline">Remember my preference</label>
</div>
<button type="submit" class="btn btn-primary my-1">Submit</button>
</form>
<form class="d-flex flex-row align-items-center flex-wrap">
<label class="my-1 me-2" for="inlineFormCustomSelectPref">Preference</label>
<select class="form-select my-1 me-sm-2 w-auto" id="inlineFormCustomSelectPref">
<option selected>Choose...</option>
</select>
<div class="form-check my-1 me-sm-2">
<input type="checkbox" class="form-check-input" id="customControlInline" />
<label class="form-check-label" for="customControlInline">Remember my preference</label>
</div>
<button type="submit" class="btn btn-primary my-1">Submit</button>
</form>
form-group
、 form-row
和 form-inline
类正如其他人所提到的,类 form-group
, form-row
和 form-inline
在 Bootstrap 5 中被删除。下面是如何替换它们:
form-group
can be replaced with mb-3
, since it previously applied the property margin-bottom: 1rem
which the mb-3
class will do by default as well .form-row
row
。form-inline
: d-flex flex-row align-items-center flex-wrap
。希望这可以帮助!
原文由 Matt 发布,翻译遵循 CC BY-SA 4.0 许可协议
3 回答5.1k 阅读✓ 已解决
5 回答2k 阅读
2 回答1.9k 阅读✓ 已解决
1 回答3k 阅读✓ 已解决
3 回答2.4k 阅读
4 回答2.2k 阅读
2 回答982 阅读✓ 已解决
原因是
form-group
、form-row
和form-inline
类已在 Bootstrap 5 中删除:https://getbootstrap.com/docs/5.0/migration/#forms
所以应该使用 Grid 和 Utilities 来代替。
…但如果您正在寻找快速解决方案,以下是这些类在 Bootstrap 4 中的工作方式: