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

Access an HTML element and using JavaScript to make changes to it

As a new web developer, I am eager to create a grid of file upload zones on my site. I have decided to use DropZone.js for this project. I have customized DropZone and added multiple drop zones in the HTML. The grid layout consists of four rows with four ...

The vertical tab layout in HTML and CSS is experiencing an issue where the active tab is not being shown above the

Currently, I am developing a web page featuring vertical tabs where each tab corresponds to an image and some content. However, the problem lies in the fact that the active tab is not displaying above the image as expected. In my attempt to resolve this i ...

Can you explain the concept of fallback color in CSS?

Can you explain to me what a fallback color means? I searched online and found out that it is used to display a color when the specified format is not supported by browsers, like Internet Explorer. Is there anything else I should know about fallback colors ...

Here's a guide on making a GET request to the Open AI API using Next.js 14

I'm attempting to send a basic GET request to the OpenAI GPT API using Next.js 14 and then simply show the results in the console, but I am encountering this error: Failed to parse URL from /api/codelang Below is the code snippet from app/test/page.j ...

next-js module for easy integration on external site

Looking to create a feature where merchants can embed the merchant calendar page on their own website using a script, similar to Calendly. Struggling with webpack configuration and looking for guidance on how to achieve this functionality for a single page ...

Modifying the title of a webpage with a Bootstrap design

As a newcomer to HTML/CSS, I recently utilized a Bootstrap theme from Themezy to build my personal website. The template includes a navigation bar with tabs labeled Top, Work, Portfolio, and Contact. I felt the need to change Top to About, so I replaced ...

Extracting textual information from Wikipedia through iframes?

Currently, I am working on a website project utilizing Squarespace. This site will feature multiple pages dedicated to individuals who have reached a level of notability worthy of having their own Wikipedia page. With over 150 pages planned, manually writi ...

Tips for customizing your MUI slider design

import * as React from "react"; import Box from "@mui/material/Box"; import Slider from "@mui/material/Slider"; function valuetext(value) { return `${value}°C`; } export default function RangeSlider() { const [value, se ...

Inconsistency with Mobile Viewport Problem

Apologies for the chaos below, but I've spent quite some time attempting to fix this on my own. It's time to surrender and seek assistance! Here are some screenshots to illustrate the issue: The problem is that sometimes the webpage functions c ...

reversing an array does not have an effect

Whenever I attempt to reverse the order of my array using the reverse() function, the changes do not reflect in the view until I make a change to the file and save it. Items.js: import { useState } from "react"; const Items = (props) => { ...

Is there a way in Material UI to dynamically update the border color of a TextField once the user inputs text?

Is there a way to style the border of a TextField only when it has text input? I am currently using the outlined version of the TextField, which displays placeholder text when empty. <TextField variant="outlined" /> So far, I have managed ...

Exploring the Power of JQuery with Hover Effects and SlideToggle

I was struggling to keep the navbar displaying without it continuously toggling when my pointer hovered over it. I just wanted it to stay visible until I moved my pointer away. <script> $(document).ready(function(){ $(".menu-trigger").hover(funct ...

The beforePopState event in next/router is not triggering as expected

Noticing an issue where the beforePopState event is not triggering when I use the back button. This code snippet is part of a hook defined in _app.js according to the documentation. The current version being used is 12.1.5 If anyone has insights on what ...

What are the steps to utilize vue.js for dynamically adjusting my sidebar based on a URL input?

Greetings to the amazing community of Vue.js enthusiasts, I am a novice looking to develop a single-page web application using vue.js. This application will consist of a fixed header and dynamic body content that changes based on user interactions. Here&a ...

On smaller screens in portrait mode, CSS automatically incorporates margin adjustments

Here is the code I am working with: <html> <head> <style> body { margin: auto; width: 720px; } </style> </head> <body> <p>Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ip ...

Generate several invoices with just a single click using TypeScript

I'm interested in efficiently printing multiple custom HTML invoices with just one click, similar to this example: Although I attempted to achieve this functionality using the following method, it appears to be incorrect as it prompts the print dialo ...

Having trouble with the full-screen feature not functioning properly?

I am currently in the process of creating a custom video player and I need to include a full-screen button. However, when I click on it, the video does not expand to fill up the entire screen. I am using javascript, css3, and html5 for this project. Any as ...

How can I create a static navigation bar and sidebar using Bootstrap 4?

Currently, I am utilizing HTML, Javascript, Bootstrap, and CSS to develop a fixed navbar and sidebar for our system. My objective is to ensure that the navbar and sidebar remain fixed even when users scroll down the page, while also maintaining responsiven ...

The horizontal overflow in the HTML code was unsuccessful

I stumbled upon an interesting issue where I applied a div with specific styling: overflow-x: scroll However, the outcome was not as expected. Instead of overflowing, the content simply started on a new line. Here is the source code for reference: & ...

Navigating between articles using React.js and Next.js

Imagine a scenario with two articles (for the complete example, visit https://github.com/codebushi/nextjs-starter-dimension/blob/master/components/Main.js) import PropTypes from 'prop-types'; class Main extends React.Component { render() { ...