What is the best way to combine a custom CSS class and a bootstrap class to style an element in next.js?

In the following example, the CSS class is imported and then applied to the element:

import customStyles from "./Home.module.css";

<div className={(customStyles.collection, "card")}>

Although they work individually, when combined as shown above, the styles are not applied to the element.

Answer №1

To add your dynamic class name using template literal, you can try:

import styles from "./Home.module.css";

<div className={`${styles.custom} card`}>

If you prefer, you can also use a utility like clsx:

import c from 'clsx';
import styles from "./Home.module.css";

<div className={c(styles.custom, "card")}>

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

Achieve full height without scrolling in React

I am facing an issue where the height:100% property is not working to fill the remaining area on the screen. A red outlined area represents the border radius, while the highlighted yellow space should have been filled: https://i.stack.imgur.com/ZQNkw.png ...

Stop my ::after element from interfering with my select dropdown menu

Check out this JSFiddle I created to showcase my issue: JSFiddle I am currently working on a customized dropdown menu using an icomoon icon instead of a V. While the design looks great, the ::after pseudo-element for the parent container is causing issues ...

Protecting the build directory while implementing actions/checkout@v2

My self-hosted GitHub runner is configured to deploy a Next.js app by checking out the repository, building, and restarting pm2. The issue arises when the actions/checkout@v2 step triggers, as it deletes all files in the repository, including the crucial ...

Guide on setting up an API route in Next.js to efficiently transmit a CSV file to the frontend

From what I understand (please correct me if I'm mistaken), the usual process for downloading a file involves the frontend making a call to an API route, with most of the operations occurring on the server side. My current task involves reading data ...

unable to gather information from suppliers

I'm currently building a login page with nextjs and spotify js, but I've run into the following error Here is the code snippet that is causing the issue: import React from 'react' import { getProviders , signIn } from "next-auth/r ...

Prevent server-side rendering of useStyles in Material UI with Next.js

I am currently in the process of developing a specific page in my application that requires access to the window object for styling purposes. I have come to understand that for a component that is not supposed to be rendered on the server, simply using &l ...

Filtering a collection in Firestore using the `where()` method for a context provider in Next.js

i encountered an issue: when using the useEffect function to retrieve my firestore documents, it works well. Currently, I am fetching all "profiles" documents (3 in total). However, I now want to only retrieve the documents where the field "workerProfile" ...

Create a canvas and include input boxes in an HTML document

I'm attempting to create a canvas line diagonally above two textboxes that are also positioned diagonally (similar to Samsung's pattern passcode) when a button is clicked, but I am facing difficulties in achieving this. I have attempted to solve ...

Creating visually appealing definition lists

My goal is to customize the appearance of a shopping cart that is created by a rigid system where I cannot modify the html code. The categories list is generated in the following manner: <dl id='dlCatLvl1' class='clsCatLvl1 clsOffCat1&ap ...

Whenever the user hits the "Enter" key, a new element will be generated and added to the bottom of an existing element

I am in need of creating a new element at the end of another element. For instance, let's say I have this element: <div id="elmtobetrig">Element that should be followed by another element when the user hits enter after this text. <! ...

Tips for troubleshooting grid display issues in Internet Explorer

.container{ display: grid; grid-template-columns: minmax(200px, 7fr) 4.4fr; grid-column-gap: 64px; } .item{ background: red; height: 100px; } <div class="container"> <div class='item item-1'></div> <div class=&a ...

Tips for Positioning Content in the Center of a Bootstrap Div

I'm struggling to center the jackpot-item-container div within a chart. Can anyone help me figure this out? Check out my code on CodePen. <div id="jackpot-container" class="col-sm-12"> <div id="jackpot-item-container"> <span id= ...

What are the best practices for protecting a web application with login and database in the year 2022?

My knowledge of security is outdated and I am looking to update my skills in full stack development. Currently, I am exploring Oauth2, JWT, Next.JS, Auth0, and more, but I am struggling to integrate all these components together. Please bear with me as I m ...

Break up in the middle of a sentence: Material UI

Currently facing an issue where my sentences break in the middle. Working with Material UI requires manual styling of different components like MUI. The problem I'm encountering can be seen below. I tried removing the display: flex, but then the squar ...

Modify the color of the components in Select from Material-UI

After reviewing numerous questions and answers on this topic, I have yet to find a suitable solution for my issue. Seeking guidance from the community for assistance. Utilizing the Select component from @mui/material to showcase the number of records per ...

The Infinite Loop: Unveiling the En

I'm interested in creating a unique shape resembling the symbol of infinity using CSS, SVG, or Canvas. If you're unfamiliar with what an infinity symbol looks like, here's an example: https://i.stack.imgur.com/cLhBh.jpg So far, I've a ...

The Next.js bundle analyzer is failing to generate pages for viewing bundles

I'm currently working on optimizing the bundle size of my website by utilizing https://www.npmjs.com/package/@next/bundle-analyzer However, when I execute npm analyze with "analyze": "cross-env ANALYZE=true next build", The HTML ...

Encountered an issue retrieving two rows nested within a parent row using Bootstrap 4 and VueJs

Currently, I am working on a VueJs and Bootstrap4 component where my aim is to achieve a design similar to the one shown using the available bootstrap classes. After going through the documentation, I came across the customized classes h-75 and h-25 provi ...

Article with content surpassing the boundary of its parent container

I'm struggling to contain text within the parent's div as it keeps overflowing. I attempted using element.style { text-overflow: ellipsis; overflow: hidden; } but unfortunately, it didn't work. Take a look here at my JSFiddle link. It ...

When attempting to create a user through webhooks, the data is not successfully transmitted to the MongoDB

`I am currently constructing a website using the latest version of Next.js (v14) with app router. For the login functionality on my website, I am implementing clerkId and webhooks. The goal for my website is to save user information to a MongoDB database w ...