如何使用 Tailwind CSS 删除输入类型 Number 上的箭头

发布于 2025-01-10 11:05:40 字数 192 浏览 0 评论 0原文

我有一个数字类型的输入,我想删除默认情况下附带的增量/减量箭头。我如何使用 Tailwind CSS 做到这一点?我查了一下,但没有发现任何可以解决这个问题的方法。

 input type="number" placeholder="Numéro de téléphone" className="border p-4 outline-none"

I have an input of type number, and I want to remove the increment/decrement arrows that come with it by default. How can I do that with Tailwind CSS? I looked up for it but found nothing that solves this problem.

 input type="number" placeholder="Numéro de téléphone" className="border p-4 outline-none"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

黯然#的苍凉 2025-01-17 11:05:41

所以我找到了解决方案 ->在你的 global.css 上你必须添加

@layer base {
  input[type="number"]::-webkit-inner-spin-button,
  input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }
}

So i found the solution for this -> On your global.css you have to add

@layer base {
  input[type="number"]::-webkit-inner-spin-button,
  input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }
}
梦中的蝴蝶 2025-01-17 11:05:41

发现了一种纯类方法,可以在 Firefox 和 Chrome 上使用,

<input
  type="number"
  class="[appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none" 
  />

感谢这些参考:

Discovered a pure class way to do this that works both with Firefox and Chrome

<input
  type="number"
  class="[appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none" 
  />

Thanks to these references:

反目相谮 2025-01-17 11:05:41

添加到@Tyron 答案是正确的。

     @layer base {
        input[type='number']::-webkit-outer-spin-button,
        input[type='number']::-webkit-inner-spin-button,
        input[type='number'] {
          -webkit-appearance: none;
          margin: 0;
          -moz-appearance: textfield !important;
        }
     }

添加与 Mozilla

参考的兼容性 w3schools/howto/howto_css_hide_arrow_number

Adding to @Tyron answer which is correct.

     @layer base {
        input[type='number']::-webkit-outer-spin-button,
        input[type='number']::-webkit-inner-spin-button,
        input[type='number'] {
          -webkit-appearance: none;
          margin: 0;
          -moz-appearance: textfield !important;
        }
     }

Add compatibility to Mozilla

ref w3schools/howto/howto_css_hide_arrow_number

昵称有卵用 2025-01-17 11:05:41
/** @type {import('tailwindcss').Config} */
const plugin = require('tailwindcss/plugin')
module.exports = {
  plugins: [
    require("@tailwindcss/forms")({
      strategy: 'class', // only generate classes
    }),
    plugin(function ({ addUtilities }) {
      addUtilities({
        '.arrow-hide':{
          '&::-webkit-inner-spin-button':{
            '-webkit-appearance': 'none',
            'margin': 0
          },
          '&::-webkit-outer-spin-button':{
            '-webkit-appearance': 'none',
            'margin': 0
          },
        }
      }
      )
    })
  ],
}

将其添加到您的 tailwind config.js 中并用作普通的 tailwind 类。

/** @type {import('tailwindcss').Config} */
const plugin = require('tailwindcss/plugin')
module.exports = {
  plugins: [
    require("@tailwindcss/forms")({
      strategy: 'class', // only generate classes
    }),
    plugin(function ({ addUtilities }) {
      addUtilities({
        '.arrow-hide':{
          '&::-webkit-inner-spin-button':{
            '-webkit-appearance': 'none',
            'margin': 0
          },
          '&::-webkit-outer-spin-button':{
            '-webkit-appearance': 'none',
            'margin': 0
          },
        }
      }
      )
    })
  ],
}

add this to your tailwind config.js and use as a normal tailwind class.

漆黑的白昼 2025-01-17 11:05:41
[-moz-appearance:_textfield] [&::-webkit-outer-spin-button]:m-0 [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:m-0 [&::-webkit-inner-spin-button]:appearance-none
[-moz-appearance:_textfield] [&::-webkit-outer-spin-button]:m-0 [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:m-0 [&::-webkit-inner-spin-button]:appearance-none
Spring初心 2025-01-17 11:05:41

我将其添加到我的 global.css 中以隐藏特定 className 中的箭头:

.hide-arrow[type="number"]::-webkit-inner-spin-button,
.hide-arrow[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

I add this into my global.css to hide an arrow from specific className:

.hide-arrow[type="number"]::-webkit-inner-spin-button,
.hide-arrow[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

辞别 2025-01-17 11:05:41

您可以尝试使用选择组件,输入没有箭头。

<select type="number" id="amount" name="amount">
    <option value="0">0</option>
</select>

适用于所有选择的解决方案

@layer base {
    select {
        appearance: none !important;
    }
}

适用于特定类型的解决方案

@layer base {
    select[type='number'] {
        appearance: none !important;
    }
}

使用 CDN

<style type="text/tailwindcss">
    @layer base {
        select[type='number'] {
            appearance: none !important;
        }
    }
</style>

You can try using select component, inputs don't have arrows.

<select type="number" id="amount" name="amount">
    <option value="0">0</option>
</select>

Solution for all selects

@layer base {
    select {
        appearance: none !important;
    }
}

Solution for specific types

@layer base {
    select[type='number'] {
        appearance: none !important;
    }
}

With CDN

<style type="text/tailwindcss">
    @layer base {
        select[type='number'] {
            appearance: none !important;
        }
    }
</style>
养猫人 2025-01-17 11:05:41

我将其添加到主 css 文件中以修复 tailwinds appearance-none 类:

@layer base {
    input[type="number"].appearance-none::-webkit-inner-spin-button,
    input[type="number"].appearance-none::-webkit-outer-spin-button {
        -webkit-appearance: none !important;
        margin: 0 !important;
    }

    input[type="number"].appearance-none {
        -moz-appearance: textfield !important;
    }
}

I added this to the main css file to fix tailwinds appearance-none class:

@layer base {
    input[type="number"].appearance-none::-webkit-inner-spin-button,
    input[type="number"].appearance-none::-webkit-outer-spin-button {
        -webkit-appearance: none !important;
        margin: 0 !important;
    }

    input[type="number"].appearance-none {
        -moz-appearance: textfield !important;
    }
}
臻嫒无言 2025-01-17 11:05:41
<input type="number" placeholder="Numéro de téléphone" className="border p-4
outline-none appearance-none" />

这是顺风的,这里有一个链接,你可以看一下
tailwind

并使用普通 css :

<style>
  input::-webkit-outer-spin-button,
  input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }
</style>
<input
  type="number"
  placeholder="Numéro de téléphone"
  className="border p-4
  outline-none"
/>
<input type="number" placeholder="Numéro de téléphone" className="border p-4
outline-none appearance-none" />

this with tailwind here a link you can look on it
tailwind

and with normal css :

<style>
  input::-webkit-outer-spin-button,
  input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }
</style>
<input
  type="number"
  placeholder="Numéro de téléphone"
  className="border p-4
  outline-none"
/>
墨小墨 2025-01-17 11:05:41

要删除箭头,您需要将 appearance 设置为 none (来源[https://www.w3schools.com/howto/howto_css_hide_arrow_number.asp])

如果您使用 TailwindCSS 3你可以尝试这个: https://tailwindcss.com/docs/appearance,如果您使用 TailwindCSS 2,则:https://v2.tailwindcss.com/docs/appearance

我希望这能解决您的问题。

To remove the arrows you need to set appearance to none (source[https://www.w3schools.com/howto/howto_css_hide_arrow_number.asp])

If you use TailwindCSS 3 you could try this: https://tailwindcss.com/docs/appearance, if you use TailwindCSS 2, this: https://v2.tailwindcss.com/docs/appearance.

I hope this solves your issue.

世界和平 2025-01-17 11:05:41

对于 Tailwind,您可以搜索“appearance-none”

https://tailwindcss.com/docs/appearance

这删除了不同输入类型的默认插件行为。

For Tailwind, you can search "appearance-none"

https://tailwindcss.com/docs/appearance

This removed the default addon behaviors of different input types.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文