Tips for sharing CSS from CSS module as a prop in Next.js

I am having trouble applying CSS to a component called Cards. Specifically, I want to style the #image_div div. Below is my code snippet:

team.module.css:

.grid_container{
    display: grid;
    grid-template-columns: repeat(3,auto);
}
.image #image_div{
   border-radius:100%;
    margin: 30vh;
} 

index.js:

import Image from "next/image";
import Div from "../../components/Div";
import Cards from "../../components/Cards";
import styles from "../../styles/team.module.css";
import xyz from "../../public/xyz.jpeg"

export default function Team(){
    return (
        <Div>
            <div className={`${styles.grid_container}`}>
                <Cards url={xyz} title={"XYZ"} className={styles.image}></Cards>
            </div>
        </Div>
    );
}

Cards.js:

import Image from "next/image";
import { Card } from "react-bootstrap";
import styles from "../styles/components/Card.module.css";

export default function Cards({title,url,width,height,alt,description,className}) {
  return (
    <Card className={`card col-xs-12 col-sm-4 ${styles.Card} ${className?className:null}`}>
      <div className="d-flex justify-content-center" id="image_div">
            <Image
            variant="top"
            src={url}
            width={width}
            height={height}
            alt={alt}
            className="img-card"
            />
      </div>
      <Card.Body className="card-content">
        <Card.Title className="card-title text-center">{title}</Card.Title>
        <Card.Text className="text-center">{description}</Card.Text>
      </Card.Body>
    </Card>
  );
}

Despite defining CSS in team.module.css, it seems that the styling is not being applied to the #image_div. What could be causing this issue? I would like the CSS from team.module.css to be applied without duplicating it in the Card.module.css file which pertains to Cards.js.

Answer №1

Similar to how the class selectors work, the #image_div selector is also affected by CSS Modules.

To properly target #image_div, you need to use :global() on the selector to switch to global scope.

.image :global(#image_div) {
    border-radius:100%;
    margin: 30vh;
}

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

CSS and jQuery code to create a nested dropdown menu

As a beginner in CSS and HTML, I am struggling with creating a clickable menu for devices. The menu will be nested under a hamburger icon and needs to have multiple levels of nesting. While I successfully implemented the top-level dropdown menu following a ...

Encountered a callback error while utilizing the 'withAuth' feature of the next-auth middleware during upload processing

When using middleware, no errors are shown in the console. Files are successfully uploaded to uploadthing with or without next-auth middleware, but there is an issue with the callback. Without the next-auth middleware: https://i.stack.imgur.com/snuM2.png ...

Function in Typescript that accepts either a single object or an array of objects

We frequently use a simple function declaration where the function can accept either a single object or an array of objects of a certain type. The basic declaration looks like this: interface ISomeInterface { name: string; } class SomeClass { pu ...

Set the height of the div to be the full height of the page when designing for responsiveness

For my responsive design, I am looking to have a footer that sticks to the bottom of the page while allowing the content to fill up the remaining space. You can view an example here: http://jsfiddle.net/rzjfhggu/1/ In this example, the header has a fixed ...

Encountering a module not found error while deploying my NextJS project to a personal server using npm run build

I have just finished developing a NextJS project and I am now in the process of deploying it to a staging server for testing, which is running AlmaLinux 8. I have made sure to install node version 16.8.0 on the server. After copying all the project files ...

"Unable to get the 'sticky' position to function correctly in tailwindcss

I've been experimenting with Tailwind CSS and trying to implement two sticky elements - a sticky header and a sticky sidebar. My sticky header seems to be working perfectly: <body> <header class="sticky z-50 top-0 hidden"> < ...

Combine mui-datatable with admin-on-rest

Is there a way to seamlessly integrate mui-datatable with admin-on-rest? Specifically, I am looking for the following options to be included in the list view: ability to reorder columns option to show/hide columns capability to adjust the number of displa ...

Guide for releasing a typescript package compatible with both node and react applications

I have developed an authentication library in TypeScript which I have released on npm. My goal is to make this library compatible for use in both Node.js projects and React projects created with create-react-app. However, I am facing an issue where one of ...

I am encountering an error when trying to run the command npm run dev. How can I resolve

I utilized vite to create a frontend template. The package.json resides in the frontend directory and includes development tools, but I'm encountering an error. This project involves Django and React. I am using a Python virtual environment, and the b ...

Deciphering the mechanics of collection referencing in mongoose

Today, I am delving into the world of using references in mongoose for the first time. I am trying to figure out how to save a template with a user ID. Do we need to retrieve the createdBy value from the client, or can it be inserted into the templateSchem ...

What is the best way to define a variable that captures and logs the values from multiple input variables?

Hey there, I'm a new coder working on a shopping list app. I'm trying to display the input from three fields - "item", "store", and "date" - at the bottom of the page as a single line item. I attempted to do this by creating a variable called "t ...

What is the method for increasing data in Datatables?

Is there a way to perform multiplication with Data in Datatables? Here is an example of Datatables and javascript code that I am working with: $('#xxdata').DataTable( { "destroy": true, "processing": true, "ajax": { ...

Managing mouse click events in jQuery

Here on SO, I successfully implemented the mouse down handler. Now, my goal is to separate these functions into their own file named test.js. Within test.js, the code looks like this: function handleMouseDown(e) { console.log('handleMouseDown&ap ...

JS glitch leading to oversized window dimensions - Issue with dropdown menu

I recently integrated a dropdown into my website using Foundation CSS. To see the dropdown in action, you can login with the credentials provided (username: stackoverflow password: testtest) on . However, I noticed that when logged in, the page on the rig ...

Is it possible to nest an array within a value of a Sass object?

I'm currently attempting to incorporate an array within the value of an object. $background-things: ( 'a': ['100vh', 'transparent', 'column'], 'higher': ['70vh', '#000', &ap ...

How can I embed input tag with the data-plugin attribute into a DOM element?

Can anyone help me with adding a data-plugin attribute to the "el" element using JavaScript? HTML <input type="text" data-plugin="datepicker" class="form-control" > JavaScript // Creating an input element var cellRight = row.insertCell(1); var ...

What provides quicker performance in AngularJS: a directive or one-time binding?

I need to display a static array on a webpage without Angular watching its value. With that requirement in mind, my question is: Which method is faster: using a directive to fetch a scope variable and create an HTML element with this variable as a hard-co ...

How can I reset the search input in v-autocomplete (multiple) after selecting a checkbox from the drop-down menu?

I am facing an issue with the v-autocomplete component from Vuetify. Currently, when I enter "Cali" in the search input and select "California" from the dropdown list, the "Cali" value remains in the search input field. I need the entered value to be clear ...

Utilizing SASS to retrieve the H, S, L values from a color

Is there a way to extract the H, S, L values from a hex color in SASS and assign them to separate CSS variables? $colors: ( "primary": $primary, "secondary": $secondary) !default; :root { @each $color, $value in $colors { -- ...

Hilarious rendering glitch with CSS in IE where the background image inexplicably contains the style "display: block."

Encountering a curious issue with how IE is interpreting my css. The defined style includes "background-image: url(/images/leftArrow.png); DISPLAY: block; cursor: pointer;" However, IE 7 & 8 seem to be merging background and display as one property (r ...