Я пытаюсь создать тонкий эффект нижней границы градиента для поля ввода с помощью Tailwind CSS. Я хочу добиться чего-то вроде этого:
Вот моя текущая попытка:
Конфигурация CSS попутного ветра:
// tailwind.config.js
module.exports = {
// ... other configurations
plugins: [
plugin(function ({ addUtilities }) {
const newUtilities = {
'.border-gradient': {
position: 'relative',
'::after': {
content: '""',
position: 'absolute',
left: '0',
right: '0',
bottom: '0',
height: '2px',
background: 'linear-gradient(to right, rgba(18, 242, 135, 0.1), rgba(18, 242, 135, 0.3), rgba(18, 242, 135, 0.1))',
},
},
};
addUtilities(newUtilities);
}),
],
};
Входной компонент:
<input
className = "w-full bg-transparent rounded-lg px-3 py-3.5 text-white placeholder-white/40 bg-input-gradient backdrop-blur-[5px] focus:outline-none transition border-gradient"
/>
plugins: [
plugin(function ({ addUtilities }) {
const newUtilities = {
'.border-gradient': {
'border-image': 'linear-gradient(to right, #12F287 0%, rgba(18, 242, 135, 1) 50%, #12F287 100%) 1',
'border-image-slice': '1',
},
};
addUtilities(newUtilities);
}),
],
'.border-gradient': {
position: 'relative',
'::after': {
content: '""',
position: 'absolute',
left: '0',
right: '0',
bottom: '0',
height: '2px',
background: 'linear-gradient(to right, rgba(18, 242, 135, 0.1), rgba(18, 242, 135, 0.3), rgba(18, 242, 135, 0.1))',
},
},
Ожидаемый результат: тонкая градиентная граница внизу поля ввода, переходящая от прозрачного к светло-зеленому (#12F287) и обратно к прозрачному, как на этом изображении:
Фактический результат: граница либо не появилась вообще, либо отображалась сплошным цветом, а не градиентом, как показано ниже:






border-color обычно не может быть градиентным цветом. Однако можно использовать псевдоэлемент, чтобы добавить элемент, похожий на границу, в позицию relative-absolute.
В Tailiwind вы можете выбрать эти псевдоэлементы, используя before: или after::
<script src = "https://cdn.tailwindcss.com/3.4.5"></script>
<div class = "flex min-h-dvh items-center justify-center">
<button class = "relative w-64 bg-sky-50 p-4 before:absolute before:inset-x-0 before:bottom-0 before:h-1 before:bg-gradient-to-r before:from-transparent before:via-green-500 before:to-transparent">Content</button>
</div>ДЕМО на Tailwind Play.
Обновите пример, используя input:
<script src = "https://cdn.tailwindcss.com/3.4.5"></script>
<div class = "flex min-h-dvh items-center justify-center">
<div class = "relative w-64 bg-sky-50 before:absolute before:inset-x-0 before:bottom-0 before:h-1 before:bg-gradient-to-r before:from-transparent before:via-green-500 before:to-transparent">
<input class = "h-full w-full p-4" placeholder = "Lorem ipsum..." />
</div>
</div>ДЕМО на Tailwind Play.