使用 tailwind css 设计表单时,您可能希望从数字输入字段中删除默认箭头(也称为旋转器)。这些箭头可能会干扰自定义设计,并且很难在不同浏览器中保持一致的样式。
在本教程中,我们将探索如何使用 tailwind css 实现这一点,包括内联样式和全局 css 方法。
问题
默认情况下,浏览器会向 元素添加递增和递减箭头。虽然功能齐全,但这些箭头经常与自定义设计发生冲突,并且很难在各种浏览器中统一样式。
解决方案
我们将使用 tailwind css 实用程序类来删除这些箭头并创建干净的、自定义的数字输入。我们还将研究如何在全球较大的项目中应用此样式。
内联方法
让我们从一个使用内联 tailwind 类的示例开始:
<form class="max-w-md mx-auto mt-8 p-6 bg-white rounded-lg shadow-md"> <div class="mb-4"> <label for="quantity" class="block text-sm font-medium text-gray-700 mb-2">quantity</label> <input type="number" id="quantity" name="quantity" class="block w-full px-3 py-2 bg-white border border-gray-300 rounded-md text-sm shadow-sm focus:outline-none focus:border-sky-500 focus:ring-1 focus:ring-sky-500 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"> </div> <div class="mb-4"> <label for="price" class="block text-sm font-medium text-gray-700 mb-2">price</label> <input type="number" id="price" name="price" step="0.01" class="block w-full px-3 py-2 bg-white border border-gray-300 rounded-md text-sm shadow-sm focus:outline-none focus:border-sky-500 focus:ring-1 focus:ring-sky-500 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"> </div> <button type="submit" class="w-full bg-blue-500 text-white py-2 px-4 rounded-md hover:bg-blue-600 transition-colors"> submit </button> </form>
网友留言2