Having trouble importing CSS in ReactJS?

While working on my project based on next.js, I encountered a situation where loading CSS in other pages was successful:

import css from './cssname.css';

<div className={css.myclass}></div>

However, now that I am implementing a lightbox component from this link, I needed to import the necessary CSS file like this:

import "react-popupbox/dist/react-popupbox.css"

The problem arises when the CSS does not apply correctly in my code. Below is the complete code which I copied from the documentation's first example:

import React ,{Component} from 'react';
import { PopupboxManager, PopupboxContainer } from 'react-popupbox';
import "react-popupbox/dist/react-popupbox.css"

class lightbox extends Component{

    constructor(props){
        super(props)

        this.openPopupbox = this.openPopupbox.bind(this);
    }

    openPopupbox(){
        const content = (
            <div>
              <p>Work like you don't need the money.</p>
              <p>Dance like no one is watching.</p>
              <p>And love like you've never been hurt.</p>
              <span>― Mark Twain</span>
            </div>
          )
          PopupboxManager.open({ content })
    }

    render(){
        return(
            <div> 
                <button onClick={this.openPopupbox}>Click me!</button>
                <PopupboxContainer/>
            </div>
        )
    }
}

export default lightbox

Answer №1

When using NextJS, you can only import a CSS file in the pages/_app.js file. If this file does not already exist, create it and then import the CSS file there. For more information, you can refer to the documentation on Built-In CSS Support

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

Tips for customizing container maxWidth based on breakpoints with muiTheme in material-ui

Trying to wrap my head around the usage of createMuiTheme and adjusting maxWidth for different breakpoints I've set up. Currently, these are the values I'm working with: import { Container as Container_, Grid } from '@material-ui/core' ...

What is the solution to resolving unmet dependencies in react?

Having some trouble reinstalling an older react project and encountering strange errors that are difficult to decipher. I attempted to update the version of react to a newer one, but unfortunately that did not resolve the issue. Currently running npm 8.11. ...

The component <FormControl /> does not support the variant prop

It's perplexing to me why <FormControl /> doesn't seem to accept the prop variant. Even though the documentation suggests that this prop is available. import React from "react"; import { render } from "react-dom"; import FormControl from " ...

Multiplication and Division with Unit-ed Values in CSS calc() Function

Can you perform multiplication or division with unit-based values using calc() (such as 100%, 5px, etc)? For instance, I wanted to try something like this: width: calc(100% * (.7 - 120px / 100%)); Expecting it to result in something similar to (if 100% ...

Extract the content from the span element on Whatsapp Web

Currently, I am in the process of learning Python along with Selenium and have encountered a challenge. I am attempting to extract the username from the most recent message in a WhatsApp group conversation. Despite several attempts, I have been unsuccessfu ...

Send the completed form once the data has been verified

Utilizing React and Redux, I have implemented a form with validation. The validation conditions are as follows: The data is validated upon input The data is re-validated before submission All fields are mandatory, and the entered data must be valid As t ...

Display every div element if none of the links have been clicked

On my webpage at url.com/yourfirstpage/, all div elements are hidden by default with a display:none property. If we specifically target #sec1 by going to url.com/yourfirstpage/#sec1, only sec1 is displayed while the others remain hidden. But what if we acc ...

Expanding the rowspan within a table column has the effect of reducing its overall width

I have created a table with two rows, where the first row has three columns and the second row has two columns. The middle column in the first row has been set to rowspan="2". However, the issue is that it appears smaller than its intended width. .kolon ...

Heroku - JavaScript and CSS Updates Causing Loading Issues

Ruby version: 2.1.5 | Rails version: 4.1.1 For some reason, the changes I make to my JavaScript and CSS files are not reflecting on Heroku; it seems like the cached assets are still being used. I've tried removing the assets and precompiling them bef ...

Having an issue with Expo React Native where the onPress navigation.openDrawer() function is not functioning properly. I appreciate any assistance you can

I've been experiencing difficulty in opening the Drawer by pressing the header button. Despite multiple attempts, I have been unable to resolve the issue. The specific error message I am encountering is as follows: Menu.js:65 Uncaught TypeError: navig ...

How can JavaScript be used to rearrange the placement of DOM elements?

<!DOCTYPE html> <html> <head> <title></title> </head> <body> <div class="boxes"> <div class="red" style="width: 300px; height: 300px; color: red"></div> <div class="blue ...

Strange problem encountered when transferring data to and from API using Typescript and Prisma

I'm encountering a strange issue that I can't quite pinpoint. It could be related to mysql, prisma, typescript, or nextjs. I created the following model to display all product categories and add them to the database. Prisma Model: model Product ...

Tips for mastering Bulk Editing in Material-Table

Many users have expressed interest in Bulk Editing as a feature. While the current material-table library allows for opening multiple edits, it only enables editing one row at a time. Is there a way to accomplish bulk editing and edit multiple rows simul ...

Prevent the cursor from exiting the div element when the tab key is pressed

Currently, I have implemented a search input box allowing users to either enter a value or select from a list of suggestions. The issue arises when the user selects an option using the tab key, as it causes the cursor to move outside the input box despite ...

Utilizing React Material-UI in an ASP.net MVC setup: A comprehensive guide

I am currently facing a challenge with integrating Material UI into my React project. The issue lies in the fact that Material UI can only be used with node package manager (npm), while my ASP.net MVC 4 project relies on Nuget as a package manager. This li ...

How can the table header be displayed only once within the map function in React JS?

I am currently working on displaying tabular data in the UI using React and TailwindCSS. The issue I am facing is that when I use a map function to iterate over the data, the header is being displayed after each row in the table. How can I ensure that the ...

Tips for integrating a vertical menu with button icons and subcategories

Currently working on a project with Twitter Bootstrap and looking to create a specific sidebar setup. My goal is to include subcategories using an accordion and a collapsible menu for mobile devices. I came across a similar implementation at http://jsfiddl ...

"Can someone point me to the location of the onScroll event within Material

I have been unable to locate any information in the Material UI documentation that addresses how to trigger a function on scroll using the onScroll event. All of my components follow either a functional and stateless approach or they are container componen ...

Internet Explorer 8 comes with excess padding at the top and bottom, causing un

Why is IE 8 adding unnecessary padding to a div? I have checked the styling and nothing seems out of place. Can someone assist with this issue? Html The highlighted div in blue is the main concern. .block { clear: both; } .inline { float: lef ...

What is the best way to test my actions, state, and user interface while incorporating the context API and utilizing tools like Jest and Testing Library?

Within my app, I have Context that wraps around it providing some state. To access the state and dispatch in my components, I utilize custom hooks called useMyState and useMyDispatch. The actions within my app are quite substantial, handling the majority o ...