Creating a personalized gradient using Tailwind CSS and Daisy UI framework

I’m attempting to incorporate a unique gradient into my next.js application with the help of Tailwind CSS and Daisy UI.

Below is the specific code snippet I plan on using:

background: linear-gradient(180deg, rgba(192, 192, 192, 0.04) 0%, rgba(201, 180, 180, 0.04) 54.5%, rgba(0, 0, 0, 0.04) 100%);

I’ve been experimenting with this custom gradient:

//Tailwind CSS configuration

import type { Config } from "tailwindcss";

const config: Config = {
content: [
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
],
daisyui: {
themes: [
{
lightTheme: {
'primary': '#757575',
'base-100': '#FFFFFF',
'secondary': '#b0cfff',
'base-content': '#e0e0e0',
'base': '#f0f0f0',
'success': '#aee5c8',
'warning': '#ffcc99',
'error': '#ff9999',
}
,
{
darkTheme: {
'primary': '#3670FF',
'secondary': '#DD5587',
'neutral': '#2a323c',
'success': '#62d993',
'warning': '#ff993a',
'error': '#fc3c3b',
// Custom colors
'left-panel-bg1': 'rgba(192, 192, 192, 0.04)',
'left-panel-bg2': 'rgba(201, 180, 180, 0.04)',
'left-panel-bg3': 'rgba(0, 0, 0, 0.04)',
},
}
],
},
theme: {
extend: {
backgroundImage: (theme) =>({
'custom-gradient': "linear-gradient(180deg, ${theme('primary')} 0%, 
${theme('left-panel-bg2')}) 54.5%, ${theme('left-panel-bg3')} 100%)",
}),
}
},
plugins: [require("daisyui")],
};
export default config;

I attempted to apply the gradient within the component.

<div className="bg-custom-gradient"></div>

Unfortunately, it isn’t functioning as expected.

Please advise me on what could be causing this issue.

Thank you!

Answer №1

In my opinion, it would be optimal to establish the color definitions in a separate constant outside of the tailwind configuration. This is particularly important because I believe it's not feasible to access values from the daisyUI plugin within tailwind and vice versa:

import type { Config } from 'tailwindcss'

const COLORS = {
  lightTheme: {
    primary: '#757575',
    'base-100': '#FFFFFF',
    secondary: '#b0cfff',
    'base-content': '#e0e0e0',
    base: '#f0f0f0',
    success: '#aee5c8',
    warning: '#ffcc99',
    error: '#ff9999'
  },
  darkTheme: {
    primary: '#3670FF',
    secondary: '#DD5587',
    neutral: '#2a323c',
    success: '#62d993',
    warning: '#ff993a',
    error: '#fc3c3b',
    // Custom colors
    'left-panel-bg1': 'rgba(192, 192, 192, 0.04)',
    'left-panel-bg2': 'rgba(201, 180, 180, 0.04)',
    'left-panel-bg3': 'rgba(0, 0, 0, 0.04)'
  }
} as const

const config: Config = {
  content: [
    './src/pages/**/*.{js,ts,jsx,tsx,mdx}',
    './src/components/**/*.{js,ts,jsx,tsx,mdx}',
    './src/app/**/*.{js,ts,jsx,tsx,mdx}'
  ],
  daisyui: {
    themes: [
      {
        lightTheme: {
          primary: COLORS.lightTheme.primary,
          'base-100': COLORS.lightTheme['base-100'],
          secondary: COLORS.lightTheme.secondary,
          'base-content': COLORS.lightTheme['base-content'],
          base: COLORS.lightTheme.base,
          success: COLORS.lightTheme.success,
          warning: COLORS.lightTheme.warning,
          error: COLORS.lightTheme.error
        },
        darkTheme: {
          primary: COLORS.darkTheme.primary,
          secondary: COLORS.darkTheme.secondary,
          neutral: COLORS.darkTheme.neutral,
          success: COLORS.darkTheme.success,
          warning: COLORS.darkTheme.warning,
          error: COLORS.darkTheme.error,
          // Custom colors
          'left-panel-bg1': COLORS.darkTheme['left-panel-bg1'],
          'left-panel-bg2': COLORS.darkTheme['left-panel-bg2'],
          'left-panel-bg3': COLORS.darkTheme['left-panel-bg3']
        }
      }
    ]
  },
  theme: {
    extend: {
      backgroundImage: {
        'custom-gradient': `linear-gradient(180deg, ${COLORS.darkTheme.primary} 0%, ${COLORS.darkTheme['left-panel-bg2']} 54.5%, ${COLORS.darkTheme['left-panel-bg3']} 100%)`
      }
    }
  },
  plugins: [require('daisyui')]
}

export default config

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The mobile navigation panel fails to open

I have a menu that I would like to toggle hide/show by adjusting its top position. Before logging in, the menu is structured as follows: <div class="lc"> <h1><a href="./"><img src="logo.png" /></a></h1> <a h ...

Issue with HTML and CSS where the header is displayed behind the rest of the content

I'm having issues with creating a fixed header for my webpage. It seems to be hiding behind the rest of the content on the screen even though I have tried adjusting the z-index without success. Here is a snippet of my HTML code: body { m ...

What is the process for submitting information to my Next.js API endpoint?

As part of my learning journey with Next.js, I am currently developing a test e-commerce website. To enhance the functionality, I am integrating a checkout system using Stripe. Initially, I was able to successfully implement the checkout feature with stati ...

Chromium CSS blend mode problem

Can anyone help me create a Photoshop overlay effect on my website? My code works perfectly in Firefox, but it's not functioning correctly in Chrome. Here's the demo. This is my current code: HTML <img src="http://lorempixel.com/output/fash ...

Bootstrap 5.3 does not allow custom background colors to take precedence

Ever since the update to Bootstrap 5.3.1, I've been facing an issue where two custom background colors are not overriding the colors set by Bootstrap, even when using !important. Strangely enough, they were working fine before the update. Here are my ...

Text that doesn't appear overwhelming in a Framer Motion text reveal animation

As a newcomer to Framer Motion, I recently attempted to create a Stagger Text effect and a Text Reveal Animation for my portfolio based on various articles. However, despite trying multiple examples, I have encountered an issue where the animation occurs s ...

`Issues with CSS/JQuery menu functionality experienced in Firefox`

After creating a toggleable overlay menu and testing it in various browsers, including Internet Explorer, everything seemed to work fine except for one major issue in Firefox (version 46). The problem arises when toggling the overlay using the "MENU" butt ...

Unraveling a token within Next.js middleware: a step-by-step guide

In one of my Next.js components, I am setting an encoded cookie like this: setCookie("_SYS_USER_AUTH", window.btoa(res?.data)); Now, I want to access the same cookie in a Next.js middleware function as shown below: export function middleware(req ...

Preserve text input from a multi-line textarea

Having an issue with a form that includes a <textarea>....</textarea> field. When saving the text, it displays the result in another form but as one continuous line within a paragraph <p>...</p>. The problem arises when trying to e ...

Tips for updating the name of a variable (such as 'data') following the process of destructuring, like with the

If I have 2 SWR hooks in the same function (or some other hook that contains a data variable), export default function Panel() { const { data, error } = useSWR("/api/customer", fetcher); const { data, error } = useSWR("/api/user", fetch ...

Designing the Mailchimp signup form with React styling techniques

I downloaded the NPM React module for Mailchimp from this link: https://www.npmjs.com/package/react-mailchimp-form. It works well and provides all the necessary forms, but I'm having trouble customizing its style. The documentation suggests adding a ...

Learn the steps to successfully rotate the custom icon in Material-Ui select without impacting its functionality and making sure it remains clickable

I've been trying to incorporate my own icon for the material UI select component. I successfully replaced the default icon using the "IconComponent" attribute in MU select. However, I'm facing issues with the new icon not rotating when the menu ...

The image does not automatically adjust size when the window is resized

I'm having an issue with my HTML and CSS code that is supposed to display two images side by side and resize when the browser window shrinks, but it's not working as expected. Even after removing all classes on the parent divs, the images still ...

I am unable to implement code coverage for Cypress in Debian at the moment

Having trouble obtaining code coverage results using Cypress in my Virtual Machine (Debian Bullseye), but no issues when I run the same project on my Windows machine. On Linux, the code coverage shows up as: Click here to view Index.html inside lcov-repor ...

Next.js React library for resizing and cropping images

I am looking for a React library that can take an image (for example, 500w by 1000h) and automatically crop it to 256w by 144h while following the behavior of object-fit: cover. I need the cropped image to be served back in base64 format. Despite English ...

Positioning of background images

My goal is to display a full background image on a website, ensuring that the bottom of the image aligns with the bottom of the browser window without any cropping. I want the image to be positioned at the bottom left corner, cutting off anything above o ...

"Rearranging the Firefox ghost image by dragging and dropping it

My drag and drop game is working perfectly on all browsers except for Firefox. In Firefox, the ghost image that appears when an item is dragged seems to be positioned very far away from the cursor. Although the ghost image can still be seen on the page, it ...

Is there a way to choose columns 2 to 6 of the row that is currently selected

I am looking to create a hover effect for columns 1 through 7 of a row where, when the user hovers over any column within that range, certain styles are applied to all columns in the row except for columns 1 and 7. This means that the background color shou ...

I designed my radio buttons to ensure they cannot be selected multiple times

I have developed a basic React custom controlled radio button: export const Radio: FC<RadioProps> = ({ label, checked, onChange, disabled, }) => { const id = useId(); return ( <div> <label htmlFor={id} ...

Adjusting the size of the snap increments

When using gridstack, I have the ability to resize my widgets. However, I've noticed that when dragging on the widgets' handles, they snap to specific sizes, which seems to be a fixed amount. If I wanted to set the widget's size to something ...