html - 如何删除输入中输入类型 "number"中的箭头?

标签 html css input tailwind-css

我想在输入焦点时删除箭头,但我无法使用 CSS 文件。我必须在我的组件上执行此操作。

我怎样才能做到这一点? TailwindCSS 可以吗?

Tailwind Playground

const InputCounter = ({ id, label, value }: NumericInputProps) => {
  const [count, setCount] = useState(value ?? 0);

  return (
    <div className="hk-flex hk-flex-col hk-gap-2">
      <label htmlFor={id} className="hk-text-sm hk-font-bold hk-text-neutral-700">
        {label}
      </label>

      <div>
        <button
          type="button"
          className="hk-h-10 hk-w-10 hk-bg-transparent hk-rounded hk-rounded-r focus:hk-outline-none"
          onClick={() => setCount(count - 1)}
        >
          <IconLess width={16} height={16} />
        </button>

        <input
          id={id}
          type="number"
          value={count}
          className="hk-h-10 hk-w-16 hk-text-center hk-text-base hk-border-none hk-rounded focus:hk-outline-none hk-appearance-none"
        />

        <button
          type="button"
          className="hk-h-10 hk-w-10 hk-bg-transparent hk-rounded hk-rounded-l focus:hk-outline-none"
          onClick={() => setCount(count + 1)}
        >
          <IconPlus width={16} height={16} />
        </button>
      </div>
    </div>
  );
};

最佳答案

[&::-webkit-inner-spin-button]属性与appearance-none实用程序结合使用。

如您所见here-webkit-inner-spin-button 定义您要禁用的箭头:

The ::-webkit-inner-spin-button CSS pseudo-element is used to style the inner part of the spinner button of number picker input elements.


以下作品:

<input id="{id}" type="number" value="0" class="[&::-webkit-inner-spin-button]:appearance-none" />

使用您的代码:

<div class="flex items-center border border-neutral-300 w-fit rounded m-8 ">
  <button type="button" class="h-10 w-10 rounded border-r border-gray-300 bg-transparent focus:outline-none">-</button>

  <input id="{id}" type="number" value="0" class="h-10 w-16 text-center  [&::-webkit-inner-spin-button]:appearance-none" />

  <button type="button" class="h-10 w-10 rounded border-l border-neutral-300 bg-transparent focus:outline-none">+</button>
</div>

Tailwind-play

关于html - 如何删除输入中输入类型 "number"中的箭头?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75879418/

相关文章:

html - 显示扁平化列表项以及适合 div 的更多项的计数

python - 使用python检测HTML中图像的大小

html - 将预定义的文本放入 HTML 表单文本框中

java - 程序未读取第一个字符串输入

Javascript 两次转义双引号

javascript - 不在每个页面上包含 JS 和 CSS 文件有什么好处吗?

php - 每次提交表单时将项目添加到 xml - xmlwriter PHP

javascript - 更改 materializeCSS card-reveal 的 overflow on clicking an element contained in card

html - Safari 字体粗细问题,文本太粗

C++ 从文件中读取数字并存储在 vector 中