Linear gradient background issue not functioning properly when transitioning between screens using Next.js

Encountered an unusual issue with Next.js. My background linear gradients are not loading properly when navigating between pages.

The link in question is:

import Link from 'next/link'

<Link href='/register'>
   <a> click me </a>
</Link>

In my code, I have a div with the following style:

style={{
   background: 'linear-gradient(153.68deg, #17191D 0%, #0C152C 45.82%);',
}}

Strangely, when clicking the link, the linear gradient fails to load and the background appears as plain white. However, upon refreshing the page, the linear gradient works as intended.

*Additionally, I am using Tailwind CSS. When I apply the following class:

className='bg-gradient-to-r from-cyan-500 to-blue-500'

instead of directly styling the background property, the linear gradient displays correctly while navigating with the link.

Any assistance on how to make the style background property work would be highly appreciated!

Answer №1

To achieve this effect, you can utilize the tailwind @layer utility as demonstrated below.

  1. Firstly, navigate to globals.css and include the following code:

     @tailwind base;
     @tailwind components;
     @tailwind utilities;
    
    
    @layer{
     .backy  {
       background-image: linear-gradient(153.68deg, #17191D 0%, #0C152C
      45.82%);
      }
     }
    
    

You can then apply it like so:

<div class="h-screen w-screen p-10 text-white backy" >Hello</div>

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

Adjust the size and orientation of an image according to the dimensions of the window and the image

As I delve into HTML and Javascript, I am facing a challenge with resizing an image based on the window size. The goal is for the image to occupy the entire window while maintaining its aspect ratio during resizing. Additionally, if the window size exceeds ...

A guide on automatically aligning coordinates and adjusting the zoom level for multiple markers in react-google-maps/api

Looking to display various dynamic markers on the map based on user activity history. I aim to set the zoom level and center coordinates accurately to eliminate the need for manual scrolling. I've reviewed the documentation at , but couldn't find ...

Issue observed: React Map layer is not loading until mouseEnter event happens

The map is displayed with the color fill only when a mouse enter event occurs. How can I make it trigger on load instead? I am working with react-simple-maps, and the JSON data is successfully loading the map on mouse enter. You can find the source code ...

Developing a system mode called "night mode"

I've decided to incorporate a dark mode feature into my Wordpress theme. Creating both dark and light modes was a breeze, but now I want to add a third mode that serves as the default for pages. This new mode will automatically switch between dark a ...

I'm looking to customize the background color and font size for an accordion in Bootstrap 4 with Vue.js. Can anyone provide guidance

Hello, I am currently using an accordion with Bootstrap 4 and Vue.js. Here is the code snippet: <div class="faq_accordion" role="tablist"> <b-card no-body class="mb-1"> <b-card-header header-tag=" ...

I am experiencing a CSS display issue on the mobile version of my map leaflet where only the header and footer are visible

I am experiencing a display issue on Android and iPhone due to conflicting css commands. Here's what's happening: I am using React + React Leaflet with a header, main, and footer all set to width 100% within a parent div with body set to width an ...

Using custom woff2 fonts in Android applications created with Visual Studio Community and Cordova seems to be causing compatibility issues

Help Needed! I am facing an issue with my app created using Visual Studio Community and Cordova. Everything works perfectly when I simulate it on my PC, but when I install it on my phone, the fonts just won't display correctly. I have tried all the s ...

Can we tap into the algorithm of curveMonotoneX in d3-shape?

I'm currently using curveMonotoneX to draw a line in d3 import React from 'react'; import { line, curveMonotoneX } from 'd3-shape'; export default function GradientLine(props) { const { points } = props; const lineGenerator ...

What is the best way to represent a state with two possible fields in React using TypeScript?

There is a specific state item that can have its own value or reference another item using an ID. interface Item { itemName: string; itemValue: { valLiteral: number } | { idNumber: string }; } const indItem1: Item = { itemName: "first sample&quo ...

What is the process for setting up a subrouter using React Router v6?

This is the current React Router setup I am using: const router = createBrowserRouter([ { path: "/", element: ( <Page activeNav="home" > <Home /> </Page> ) }, { ...

Utilizing Mantine dropzone in conjunction with React Hook Form within a Javascript environment

Can Mantine dropzone be used with React hook form in JavaScript? I am currently working on a modal Upload using Tailwind components like this import { useForm } from 'react-hook-form'; import { Group, Text, useMantineTheme } from '@mantine/c ...

An error occurred when attempting to set state within a nested fetch

Having difficulty solving an issue with react.js. loadFromServer(pageSize) { fetch('http://localhost:8080/api/employees') .then(response => { return fetch('http://localhost:8080/api/profile/employees', ...

Display an element that has been tucked away, and then bring it to life

Is there a way to implement an animation that causes the hidden form to slide from right to left after the .button class is hidden? I have been able to achieve similar effects individually, but struggle with synchronizing their animations. When the butt ...

What is the best way to modify and execute js and css (less) files dynamically using ajax and jQuery?

Whenever I click a button, an ajax call is triggered to load various html code into a div with the id 'main'. While displaying the html content is not an issue, integrating and applying css and js code to my current page has proven to be challeng ...

The browser is only showing particular changes made to the CSS file

I'm currently working on a web project and have the following CSS and HTML code: style.css: body { background-color: red; font-size: 14px; font-family: Roboto,arial,sans-serif color: gray; } img { height: 92px; width: 272px; ...

Error: ReferenceError: window is not defined in webpack and ReactJS environments

Everything was running smoothly until I tried importing a css file into the component, which led to the following error. webpack:///./node_modules/style-loader/lib/addStyles.js?:23 return window && document && document.all &&am ...

How to properly align TableHeader and TableBody contents in a Material-UI table

I am experiencing an issue with a file that is supposed to display a table of data pulled from a database. Although the table does appear, all the data seems to be displayed under the ISSUE NUMBER column, instead of being aligned with their respective col ...

Reducer in Redux not receiving Action from React

I am currently working on implementing a theme using Redux in my code. Below is the code I have written: Actions/index.js export const CHANGE_THEME = 'CHANGE_THEME'; export const changeTheme = (payload) => { console.log('payload &apo ...

Tips for reactivating getStaticProps following an update:

For a personal project centered around an online shopping platform, I am working on managing the products page. I'm currently attempting to refresh the list of products after deleting one. My current setup involves using Next.JS in conjunction with Fi ...

The function cannot be called on params.getValue()

I am facing an issue while trying to retrieve the value of a specific row's column ID. The goal is to change the URL by appending the retrieved ID when clicking on an icon. However, I encountered an error stating TypeError: params.getValue is not a fu ...