Gradient not rendering properly with Tailwind

Update/TLDR: Surprisingly, the issue was not related to webpack as I initially suspected - it turns out I was accidentally overwriting the gradient classes in the configuration file.


What could be causing a gradient like this one:

bg-gradient-to-r from-purple-500 to-pink-500
to display correctly in a codepen, but not apply in my project (which uses webpack and a Tailwind config file)?

I have come across some solutions suggesting changes in the configuration file to define custom colors, but I am puzzled as to why it does not work out of the box. The element seems functional otherwise (it accepts background color changes, for example), and the classes for the gradient appear to be applied:

https://i.sstatic.net/psyil.png

Although I can make it work using this workaround, I am still new to Tailwind and wondering if I am overlooking something:

@layer{
 .grad  {
   background-image: linear-gradient(to right, #a855f7, #ec4899);
  }
 }

*Update: I have included a small repository example here. The gradient has been added to the second section.

**Update 2: Interestingly, this issue does not arise when webpack is not used - the gradient class works perfectly then. Refer to this minimal repository for comparison.

Answer №1

Sharing this solution in case someone encounters a similar issue.

After some investigation, I realized that the reason for my problem was mistakenly overriding the gradient classes with the following code:

backgroundImage: {
  'hero-pattern-desktop': "url('/src/images/bg-header-desktop.png')",
  'hero-pattern-mobile': "url('/src/images/bg-header-mobile.png')"
},

This should have been inside the extend block.

I want to give credit to the creator of Tailwind CSS for their prompt response: here.

Answer №2

Dealing with the same problem regarding my tailwind configuration

export default {
     content: ['./index.html', './src/**/*.{js,ts,jsx,tsx}'],
     theme: {
     extend: {
       backgroundImage: {
        landing: 'linear-gradient(rgba(35, 25, 23, .48), rgba(35, 25, 23, .48)), url(/src/assets/landing.jpg)',
        interior: 'linear-gradient(rgba(35, 25, 23, .48), rgba(35, 25, 23, .48)), url(/src/assets/interior.jpg)',
        church: 'linear-gradient(rgba(35, 25, 23, .48), rgba(35, 25, 23, .48)), url(/src/assets/church.jpg)',
       },
       },
    },
  plugins: [],
 };

 <div className="bg-landing"></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

What is the best way to deactivate unclicked href links within a loop?

https://i.sstatic.net/sUufY.png Looking at the template image, my goal is to disable all links that were not clicked when one of the links from 'number1' to 'number3' is clicked. For example, if 'number2' is clicked, then &ap ...

Maximizing the functionality of PHP switch to create clickable list items

I have successfully created a simple switch for my website, but I am encountering an issue with clickable list items. The concept is that when I click on any of the list items, the switch should display the appropriate greeting (whether it's Night or ...

Tips for avoiding word wrapping in text with white spaces

I am currently experiencing an issue with word-wrapping in my category names when there are two words separated by a space. Below is the CSS code snippet: .post-item .cat { height: 25px; display: inline-block; background: #CC0000; font-size: 11px; paddin ...

Is it necessary for each React component to have its own individual stylesheet?

Looking for some advice on React as a newbie here. I'm wondering whether each React component should have its own stylesheet. For instance, if I have my main App component that gets rendered to the browser, is it sufficient to include a CSS file the ...

CSS not displaying images properly

After completing my project, I organized my files by creating an HTML file, a CSS file, and an "assets" folder. Within the assets folder, I added another folder named "images" where I placed a PNG image. To link the image in my CSS file, I initially used ...

Adjust the input value with CSS when hovering

Whenever I click on a button, the name of that button is displayed on the site. However, I am looking to change this button name when hovering over it but I am not sure how to do it. echo '<form id="button" method="POST" >&ap ...

Cordova - Fixed elements flicker/blink when scrolling

I have exhausted all possible solutions, ranging from -webkit-transform: translate3d(0,0,0); to -webkit-backface-visibility:hidden but none of them seem to resolve the issue of an element flickering/blinking/disappearing when scrolling on iOS with - ...

Update the content inside the extension by modifying its innerHTML

Just starting out with JavaScript, I'm attempting to create a basic extension that can generate a random number. document.getElementById("submit").onclick = function() { a = document.getElementById("in1").value; b = document.getElementById("in2 ...

Troubleshooting problem: Scrolling problem in IE7 and IE8 with Lightbox

The lightbox I'm using works flawlessly on all browsers, except for IE. When viewed on IE, it shows triple scroll bars. Here is the CSS code for the iframe: #wrap { float:left; width:800px; height:500px; overflow-x: hidden; overflow-y: scroll; } #co ...

Using HTML and CSS to implement a broadened perspective for a specific design

https://i.stack.imgur.com/ckQHa.png Hello, I am facing an issue with a UX design that is optimized for 1200px resolution width. However, when the HTML is loaded in a browser on a larger window resolution, there is a 200px gap on the right side. How can I ...

What steps should be followed to display an HTML page within an HTML div?

The question I have is a bit misleading, as I'm not looking for guidance on how to open an HTML document in a div. Rather, I am currently facing an issue where I am unable to replace the HTML file that I have already placed in a div. Initially, I pla ...

Adding a unique styling to a div with a custom css class

I am experiencing an issue with my CSS file (approval.css) that is defined as a resource and applied to my XPage. Within the css, there is a specific line of code: .appNavBackground {background-color:#ffffd6 ;} When I try to apply this styleClass to a di ...

Is there a way I can structure this part using a grid layout?

The website I need assistance with Can someone guide me on structuring this section using Bootstrap4 Grid System? Note: Do not include the sticky navbar in the design. I appreciate any help you all can provide :) ...

Is HTML5 compatible with Google Tag Manager Custom HTML?

I recently inserted a basic HTML code into my website. <header><p>hello</p></header> However, I encountered an error stating that the HTML, CSS or script is invalid and therefore preventing me from publishing it. Does anyone have ...

Storing Form Data in MySQL, upon clicking the submit button the user is redirected to a PHP page and the information is not

Currently, I am facing an issue with injecting data into my SQL table. Whenever I input information into the forms and click on the submit button, the page redirects me to my PHP file without actually injecting any data. The tables remain empty. Below is ...

A pale tooltip with a light arrow appearing against a soft white backdrop

Can someone help me figure out how to display a white tooltip with a white arrow? I've tried to implement it using the code below, but the white color is not visible against the background. Any suggestions on making it stand out? https://i.sstatic.ne ...

Is there a way to adjust the speed of the transitions between animations?

I've been experimenting with ways to increase the time between animations in my cycle. Adjusting the duration of the keyframes animation hasn't yielded the desired effect. span { animation: rotateWordsFirst 15s linear infinite 0s; ...

Make sure PTable maintains a horizontal layout on any device with PrimeNG

When I view my Ptable on desktop or iPad, it looks like this: https://i.stack.imgur.com/ONqZV.png However, when I switch to a device like an iPhone X, it changes to this layout: https://i.stack.imgur.com/H2q7j.png I want the horizontal layout to displa ...

Instructions for passing a single value from a while loop and showing a different value in a text box through PHP

Can one value be displayed while sending another value in an Input text field simultaneously? I have a form that displays details in descending order, but when I update the details from another page, they are being updated in ascending order instead. Cod ...

Screen size is incompatible with flash player

I've been using this code to try and make a swf file fit my screen or any screen it's on, but I've run into an issue. When using this code, the player in both Chrome and IE stretches to fit the screen width, but the height remains the same, ...