Bootstrap 5.2下移除数字输入框箭头时,如何在CSS中正确覆盖-moz-appearance属性?
Let’s get that Firefox number input arrow issue sorted out! The root problem here is Bootstrap 5.2’s default styles applying appearance: none; to number inputs, which is overriding your -moz-appearance: textfield; rule—exactly what you spotted in dev tools.
Here are two reliable ways to fix this:
Option 1: Use Higher Specificity Selectors (Recommended)
Bootstrap typically applies styles to inputs via the .form-control class. We can create a more specific selector to override its default appearance rule without relying on !important:
/* Chrome, Safari, Edge, Opera */ input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; } /* Firefox - override Bootstrap's default appearance rule */ input[type=number].form-control { -moz-appearance: textfield; appearance: textfield; /* Reset global appearance to textfield for Firefox */ }
This works because the selector input[type=number].form-control has higher specificity than Bootstrap’s .form-control rule, so your styles will take precedence.
Option 2: Use !important (Quick Fix)
If you don’t want to tie the rule to the .form-control class, you can use !important to force your styles to override Bootstrap’s:
/* Chrome, Safari, Edge, Opera */ input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; } /* Firefox - force override with !important */ input[type=number] { -moz-appearance: textfield !important; appearance: textfield !important; }
Just note that overusing !important can make CSS harder to maintain long-term, so the first option is preferred when possible.
After updating your CSS, refresh Firefox and you’ll see those number input arrows are gone, matching the behavior in Chrome!
内容的提问来源于stack exchange,提问作者randoo

