Changing text color dynamically when hovered over by referencing retrieved data

Hello, I'm having trouble with applying a className based on database values and using it in CSS for custom hover color. Can anyone assist me? 🙏

For example, if the category is 'Literature' --> it should be displayed as 'literature' in lowercase. The class is assigned correctly when inspected, but the content of the class is not displaying properly:

https://i.sstatic.net/1ufW6j3L.png

Snippet from the TSX file:

<ul className={`${style.categories} ${poppins.className}`}>
    {unique_categories.map((category) => (
        <li key={category.id}>
            <Link
                href={`${category}`.toLowerCase()}
                className={`${category}`.toLowerCase()}>
                {category}
            </Link>
        </li>
    ))}
</ul>

CSS part:

.categories {
  border: 1px solid rgb(0, 0, 0);
  margin: 0 auto;
  padding: 0;
  width: 100%;
  text-align: left;
  list-style: none;
  padding: 10px;
  text-align: center;
}

.categories li {
  display: inline-block;
  margin: 0px 20px 0px;
}

.categories a {
  color: rgb(0, 0, 0);
  text-decoration: none;
  text-transform: uppercase;
}

.literature:hover {
  color: blue !important;
  text-decoration: underline !important;
}

Answer №1

When utilizing css modules in your project, the classnames returned from the import will not match what you initially wrote. For example,

.test{
  display: block;
}

The test classname may turn into something like test--a12d.
You have two options: use :global to keep the classname as is, or simply import your CSS file directly:

:global {
  .literature:hover {
    color: blue !important;
    text-decoration: underline !important;
  }
}

Alternatively, you can do this:

import 'colorClasses.css' // instead of import styles from 'colorClasses.module.css'

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 are some ways to modify the appearance of the post title table using CSS?

In this snippet of HTML code- <table style='min-width:60%;height:25px;'> <tr> <td><b><data:post.title></b></td> <td id='date-and-author' style='position: relative;bo ...

What is the best way to align social media icons at the center of the footer section?

I've been working on trying to center the social media icons in the footer, but no matter what changes I make in the code, there's been no visible difference. Can anyone offer some assistance? footer { background-color: #FFF; color: white; ...

Tips for toggling the visibility of a <div> element using PHP code inside

I'm having trouble with a dropdown list that is supposed to show/hide some divs containing PHP files. However, when I try to toggle the visibility of the divs using the dropdown list, it doesn't seem to work as expected. Can anyone help me figure ...

What are the steps to achieve such a design?

Can you show me how to create a single layout using HTML and CSS? I am struggling with splitting the screen properly. Could you provide a simple example, maybe on jsfiddle? https://i.stack.imgur.com/d2rbn.jpg Thank you in advance! EDIT: I have added a ...

Tips for dynamically updating the id value while iterating through a class

Here's the HTML snippet I am working with: <div class="info"> <div class="form-group"> <label class="control-label col-sm-2">Title</label> <div class="col-xs-10 col-sm-8"> <inpu ...

If a div is hidden, disregard this particular CSS rule

In my current scenario, I am dealing with 3 distinct divs: - Menu - Header (#rt-top-surround) - Showcase (#rt-showcase) - Main Body content (#rt-mainbody-surround) The Menu is set as 'sticky' with position: fixed. As a result, I have to adjust ...

Transitioning in CSS involves animating the changing of a CSS property over

My goal with CSS is to create a transition effect with a delay that behaves differently when entering and exiting. Specifically, I want a 1 second delay when an element enters, but no delay (0 seconds) when it exits. transition: width 0.3s ease-in 1s; tra ...

Issue with floating navigation bar functionality when resizing the page

After much tinkering, I have managed to create a floating navigation bar for my website. Most of the time, it works perfectly fine, but there's an issue when the window size is adjusted in the floating mode. Take a look at the image below for referenc ...

Issues with Bootstrap CSS functionality not functioning properly within a specific div

Seeking assistance with a Bootstrap issue. I'm attempting to convert the h1 and h3 tags "Jane (Doette and Front-End Ninja)" in my div to uppercase and align them on the right side. However, there seems to be a conflict preventing this from working pro ...

Preventing Style Inheritance in React-Select with Bootstrap Using HTML and CSS

When attempting to use react-select with Bootstrap CSS, I am encountering a styling problem. This issue may not be related to these libraries specifically. I cannot say for certain. For a demonstration of the problem I am facing, you can view this codesa ...

What is the best way to ensure that 4 divs adjust dynamically to take up 25/50/100% of the width when resized below their minimum

Imagine you want to showcase 4 images, all with square dimensions, each taking up 25% of the width. As you resize the window and they get smaller, ensure they can shrink down to a minimum width of 200px. However, if they need to be made even smaller, have ...

Is there a way to reduce the height of the border-left property in CSS?

In creating a simple address panel, I have divided it into three sections: address, phone number, and email. Each section includes an icon and a paragraph next to it. To align these sections side by side, I used the vertical-align: top and display: table p ...

Switching text appearance upon checking the checkbox

I am currently working on a Vue.js app for a To Do List. I have a feature where you can add tasks to a list, each with its own checkbox. I want to implement a feature that puts a line-through text style on an item once its checkbox is marked. Can anyone pr ...

Error in CSS styling affecting image display on responsive website

My CSS seems to have a bug when it comes to responsive pages with images. Take a look at the demo: https://jsfiddle.net/xr4getom/ If you resize the window on this example, you'll notice that a dark background (#222) appears intermittently. Is there ...

Using Material UI styling alongside Next.js may cause unexpected issues

I've been facing issues while transitioning a project from plain React to Next.js. Even after trying to copy the files to another working Next.js project, the problem persists. It appears that the project breaks consistently in production but only sp ...

Input the latest data into the Bootstrap form

Implementing the bootstrap4 framework in my web application, I have a table displaying various values. Each row includes an edit button at the end of the row (last column). The requirement is that when this edit button is clicked, a form should pop up with ...

From where was this color of the navigation bar derived?

As I delve into a site previously worked on by someone else, my task is to recreate the navigation they implemented. However, I am unable to locate in the source code what was used for the navigation background. The challenge lies in the fact that after m ...

Switching hover behavior on dropdown menu for mobile and desktop devices

I have implemented a basic JavaScript function that dynamically changes HTML content based on the width of the browser window. When in mobile view, it removes the attribute data-hover, and when in desktop view, it adds the attribute back. The functionalit ...

Is there a way to silence TypeScript's complaints about a React rendered value being converted into a Date object?

In my latest project using Next.js, TypeScript, Prisma, and Radix-UI, I'm working with a loan object that has various key-value pairs: { "id": 25, "borrowerName": "Test Borrower 1", "pipelineStage": ...

Ensure the initial div is positioned to the left while the following divs are aligned to the

I am looking to organize three distinct pieces of information in a horizontal line layout, shown below: | | | Chapter one Language: English | | ...