Utilizing gradients across various elements

Attempting to add a colorful background to the button elements inside a div, while keeping the outside background black has proven challenging. I've explored various options in Tailwind CSS documentation without success (currently using NextJS).

return (
  <div className="flex mt-10 flex-col items-center">
    <div className="relative">
      <div className="bg-gradient-to-br from-[#70d6ff] via-[#ff70a6] to-[#e9ff70]">
        <div className="p-4 font-semibold grid grid-cols-3 items-center">
          <button className="bg-transparent bg-clip-padding border rounded p-2" onClick={() => {setView(10);}}><span>Kelas 10</span></button>
          <button className="bg-transparent bg-clip-padding border rounded p-2 ml-2" onClick={() => {setView(11);}}>Kelas 11</button>
          <button className="bg-transparent bg-clip-padding border rounded p-2 ml-2" onClick={() => {setView(12);}}>Kelas 12</button>
          <div className="grid grid-cols-2 col-span-3 space-x-2 mt-2">
            <button className="bg-transparent bg-clip-padding border rounded p-2" onClick={() => {setDateYesterday();}}>Kemarin</button>
            <button className="bg-transparent bg-clip-padding border rounded p-2" onClick={() => {setDateTommorow();}}>Besok</button>
          </div>
          <button className="bg-transparent bg-clip-padding border rounded p-2 col-span-3 mt-2" onClick={handleCopy}>{copyMessage}</button>
        </div>
      </div>
    </div>
    <Display/>
  </div>
)

Is there a solution within Tailwind CSS, or is it currently not feasible?

Attempts so far involved utilizing all available bg-clip- classes within Tailwind.

Desired outcome: Implementing a reversed version of bg-clip-text, where text remains white but the colored background applies to the button element instead.

Answer №1

I made some revisions to the answer I previously provided for editing.

It can be challenging to locate the clip-path within tailwind classes.

I did a test using pure CSS once.

While it may not be the perfect solution, I hope it brings you closer to resolving the issue...!

global.css

...
/* bg-gradient-to-br from-[#70d6ff] via-[#ff70a6] to-[#e9ff70] */
button.custom-clip {
  clip-path: xywh(0 0 100% 100% round 0.25rem);
  background: white;
}

button.custom-clip:after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(to bottom right, #70d6ff, #ff70a6, #e9ff70);
  border: 1px solid white;
}

jadwalRewrite.tsx

...
    return (
        <div className="flex mt-10 flex-col items-center">
            <div className="relative">
            <div className="">
                <div className="p-4 font-semibold grid grid-cols-3 items-center">
                    <button className="custom-clip rounded border-none" onClick={() => {setView(10);}}>
                        <span className="block w-full h-full border p-2 rounded">Grade 10</span>
                    </button>
                    <button className="custom-clip rounded ml-2 border-none" onClick={() => {setView(11);}}>
                        <span className="block w-full h-full border p-2 rounded">Grade 11</span>
                    </button>
                    <button className="custom-clip rounded ml-2 border-none" onClick={() => {setView(12);}}>
                        <span className="block w-full h-full border p-2 rounded">Grade 12</span>
                    </button>
                    <div className="grid grid-cols-2 col-span-3 space-x-2 mt-2">
                        <button className="custom-clip rounded border-none" onClick={() => {setDateYesterday();}}>
                            <span className="block w-full h-full border p-2 rounded">Yesterday</span>
                        </button>
                        <button className="custom-clip rounded border-none" onClick={() => {setDateTomorrow();}}>
                            <span className="block w-full h-full border p-2 rounded">Tomorrow</span>
                        </button>
                    </div>
                    <button className="custom-clip rounded col-span-3 mt-2 border-none" onClick={handleCopy}>
                        <span className="block w-full h-full border p-2 rounded">{copyMessage}</span>
                    </button>
                </div>
            </div>
            </div>
            <Display/>
        </div>
    )

result

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

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

Issue with IE 8 compatibility and jquery

Here is the setup of my div: <div class="container"> <div id="myid" style="display:hidden;"> <p>some stuff here</p></div> </div> When I run the command $("myid").slideToggle("slow"); on the above html code (where " ...

What is the best way to ensure a div takes up the rest of the height on a page when the header's size is unpredictable

Is there a way to make the red area fill the remaining visible space without overlapping into the footer? I also need the infoContent section to be scrollable. The height of the header may vary. I came across some older solutions that suggested using Java ...

Upon clicking the navbar dropdown item, it shifts its position

I am currently working on setting up a navigation bar with multiple items aligned to the right side. However, I have encountered an issue where clicking on the "notification" icon causes the other icons in the navbar to move instead of remaining fixed in p ...

Guide to adjusting margin size according to specific screen size thresholds?

I've set up a series of reactstrap cards that are dynamically organized into rows. On "md" screen sizes and larger (bootstrap), there will be 3 cards per row, while fewer screens will display 2 cards. Here's the component: <Card outline ...

Using inline SVG as a background in a select element with Firefox for custom styling

I've been working on creating a customized select tag with an inline SVG background using -webkit-appearance: none in my CSS. For reference, here is the JSFiddle link: http://jsfiddle.net/sucrenoir/yHR53/5/ select { font-size: 30px; border: ...

Acquiring the source or domain name in Next.js

Is there a way to retrieve the origin in Next.js without using window.location.origin? The useRouter().asPath method provides the relative pathname, but how can I access the origin URL like https://www.google.com? The Next.js Router docs do not provide in ...

Tips for making a bootstrap card that matches the container's height and includes a scrollable body

I am currently working on a Bootstrap card that needs to match the height of its container. Specifically, I want the card header to be at the top, the footer at the bottom, and the body to fill the remaining space. The body should also be scrollable to acc ...

Is it possible to make the body background image adjust its size to the browser window

Looking to change the body background using a jQuery script. The goal is to scale the background image to fit the browser window size. I've come across a script called , but it seems to affect the class img and not the background-img. Any suggestions ...

Establish the Cascading Style Sheets for the Drawer-AppBar component in Material UI for React

Whenever I deploy my navbar, the 'PieDePagina' component shifts to the bottom by 144px (as defined in the STYLE.contentStyleActive). This issue is caused by the CSS modification, but I am unsure of how to resolve it. Another query I have is how ...

Steps for appending a string to a variable

Currently working on creating a price configurator for a new lighting system within homes using Angular 7. Instead of using TypeScript and sass, I'm coding it in plain JavaScript. Page 1: The user will choose between a new building or an existing one ...

Integrating a fresh element into the carousel structure will automatically generate a new row within Angular

I'm currently working on an Angular4 application that features a carousel displaying products, their names, and prices. At the moment, there are 6 products organized into two rows of 3 each. The carousel includes buttons to navigate left or right to d ...

Utilizing JavaScript to trigger the :hover pseudo-class and implement event transfers

Consider this situation: You have a scenario where two images are stacked on top of each other. The image with the highest z-index is transparent and handles click events, similar to Google's Map API, while the image below is for visual representatio ...

Exploring the Next.Js API with Jest Testing

Having trouble writing test cases for my API file using Jest with Next.js. Struggling to achieve coverage for the file despite trying various methods. ApiFile.js const axios = require('axios'); import getConfig from 'next/config'; exp ...

What is the process for moving a tap-target button with materialize css?

Looking for tips on how to relocate a tap-target button that's currently stuck in the bottom right corner of the screen. I've experimented with various methods like adjusting margins, padding, and even nesting it in an outer div, but nothing seem ...

Aligning a series of images with individual captions in the center

I am currently working on centering a row made up of four images along with their respective captions underneath. The code I am using is as follows: <div class="clear" style="text-align: center;"> <div style="float: left; padding-right: 10px;"& ...

The connection between Socket.io and the environment variable in Next.js is not working as expected

I am facing an issue where my working environment variable setup does not allow socketio to connect. The .env.local file contains the following: HOST=http://localhost:8080 In the index.js file: console.log(process.env.HOST) const socket = io(process.e ...

Center div encroaching on floated left div

https://i.sstatic.net/uwyGY.pngCan someone help me align three divs horizontally? I'm having an issue where the center div is overlapping the left div. What could be causing this problem? <div> <div style={{width:"100px", ...

Securing Next.js routes with protective middleware

In my Next.js 13.4 app, I am working on securing my routes using middleware. The issue I am encountering revolves around redirecting users based on their token status. If a user has a token, they should be redirected to the homepage, and if not, they shoul ...

Encountered an error with the application routes: A client-side exception has been intercepted

Working on a project utilizing Next.JS 14, I've been attempting to configure a modal that intercepts the admin/dashboard/customers/[customerId] route to display content within it similar to producthunt. The issue arises when an error occurs with the ...

The StreamingTextResponse feature is malfunctioning in the live environment

When I share my code, it's an API route in Next.js. In development mode, everything works as expected. However, in production, the response appears to be static instead of dynamic. It seems like only one part of the data is being sent. I'm puzzl ...