I'm not sure how to use the global .container CSS style in Next.js for multiple pages


I'm currently diving into the world of React and Next.js, tackling a project with Next.js. I've set up a global CSS file with a .container style definition which I imported in my _app.js file. However, I'm unsure how to apply this global style to a specific page. In one of my pages, I have a module.css file that I understand how to work with, but there's a div element with the global container class that I can't seem to style properly within that page. Can I define the .container property in the global CSS file or does it only affect global tags like a, img, h1, etc? I'm feeling a bit overwhelmed by the CSS aspect of Next.js.

After figuring out how to pass global CSS to a page that uses module.css, I now find myself stuck with the module CSS.

I've created a component called HeroSection like this :

import React from "react";
import style from "./heroSection.module.css";

function HeroSection({ title, paragraphs, image }) {
  return (
    <div className={style.heroSection}>
      <div className={style.text}>
        <h1>{title}</h1>
        <div className={style.paragraphes}>{paragraphs}</div>
      </div>
      <img src={image} alt="" />
    </div>
  );
}

export default HeroSection;

And on a page that contains the component and adds props:

            <HeroSection
              title="Contact Us"
              paragraphs={
                <>
                  <div className="para1">
                    <p> Let's improve this societal project together!</p>
                    <p>
                      We value your suggestions, opinions, and comments.
                    </p>
                  </div>
                  <p>
                    Right here
                  </p>
                </>
              }
              image="/images/contact.jpg"
            />

In my heroSection.module.css file, I have the following code:

.para1 {
  margin-bottom: 44px;
}

As you can see, in the page containing HeroSection, a div has the className "para1" but I'm having trouble applying the CSS styles to it. I tried using className={style.para1} without success. How can I style the div passed as props?

Answer №1

Make sure to include the CSS file on the page where you are using the <HeroSection> component.

import style from "<relative-path-to-heroSection.module.css>";

After that, assign the correct class to the <div> element below.

<HeroSection
    title="Contact Us"
    paragraphs={
        <>
            <div className={style.para1}>
                <p> Let's improve this project together!</p>
                <p>
                    We value your suggestions, opinions, and feedback.
                </p>
            </div>
            <p>It's right here</p>
        </>
    }
    image="/images/contact.jpg"
/>

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

Encountering a dependency issue while trying to build with NPM

I have been researching peer dependencies with npm, but this error that I am encountering is causing confusion. Can someone assist me in identifying the package responsible for this issue? Despite trying to follow step by step instructions from start to fi ...

Troubleshooting a problem with CSS animations disappearing

I've been experimenting with CSS animations and I've run into a bit of a snag. I'm looking to create a div that fades in with a delay - meaning it won't be visible until the animation starts. Here's what I have so far: http://jsfi ...

ensured maximum height of a div attached to the bottom

<body style="width: 100%; text-align: center;"> <div style="margin: 0 auto;">container <div style="width: 200px; margin-top: 100px; float: left;"> left </div> <div style="width: 728px; floa ...

Is there a way to automatically redirect my page after clicking the submit button?

I'm having trouble with the code below. I want it to redirect to NHGSignin.php if 'new horizon gurukul' is entered. When I click the Next button, it's supposed to take me there but it's not working as expected. Can anyone help me f ...

Tips for Incorporating the YouTube Iframe API into Your ReactJS Project

While working in React, I am attempting to build a custom YouTube player component that includes a new set of player controls. The YouTube iframe API provides the following code snippet for creating a player instance: var tag = document.createElement(&ap ...

What are the reasons behind the min and max range method not providing accurate results?

I am in need of a method that can verify if a given value falls within the valid range of -064.000000 to -180.000000 and 142.000000 to 180.000000. The structure of my ranges object is as follows: "ranges": { "range1": { "min& ...

Container that can be scrolled under varying heights

Trying to structure some CSS in order to create a website that resembles the layout of a typical desktop application: Almost there, but struggling to make the scrollable panel stick to the bottom of the viewport and show a scrollbar instead of overflowing ...

Fade out a dynamically loaded content block using jQuery

I am currently developing a small app and encountering issues with deleting (fading out) dynamically loaded div elements using jQuery. The problem occurs when adding a new content box. If the page is reloaded and the content box is rendered normally (from ...

I'm curious, what height would be most suitable for a first impression?

I'm in the process of building a website and I want to ensure that all elements are visible within the div without requiring users to scroll. However, I know that screen resolutions vary between computers. What can I do to address this issue? Is ther ...

Include the window.innerWidth value in the initial GET request

When dealing with a server-side rendered app that has responsive styling based on window.innerWidth, the challenge lies in how to pass the client's screen size in the initial GET request for index.html. This is crucial so that the server can prepare a ...

A guide to displaying API response data in a React JS application

As a beginner in react JS, I've encountered a persistent issue. Here is the code: import React from 'react'; class SearchForm extends React.Component { async handleSubmit(event){ event.preventDefault(); try{ const url ='/jobs/ ...

When padding is added on an MVC 5 page, the Bootstrap 4.1.1 class option for rounded-circle becomes distorted

Incorporating VS 2017 and bootstrap 4.1.1 into an MVC 5 page, I am facing a challenge in adding right-side padding to an image without distorting the circular shape of the image, as shown below. When I apply the padding, the circle becomes warped, but remo ...

Tips for customizing the appearance of a highlighted row in MUI5

I'm still learning the ropes with MaterialUI and have recently started using V5. While I've come across code samples for this in v4, I'm a bit unsure on how to achieve the same result in mui5. Specifically, I have a data grid where I would l ...

Transform the look of an inactive hyperlink

Can the visual style of an HTML link be modified when it is disabled? For instance, by implementing something like this: a.disabled { color:#050; } <a class="disabled" disabled="disabled" href="#">Testing</a> The code snippet above appears ...

The content momentarily flashes on the page during loading even though it is not visible, and unfortunately, the ng-cloak directive does not seem to function properly in Firefox

<div ng-show="IsExists" ng-cloak> <span>The value is present</span> </div> After that, I included the following lines in my app.css file However, the initial flickering of the ng-show block persists [ng\:cloak], [ng-cloak], ...

Unable to import global CSS in React; however, local components are working fine

My React application is having trouble loading global CSS styles. While local components are able to access their own styled-components, the global CSS styles are not being applied across all components. I have tried various import paths and different file ...

When refreshing in React-Native, the Header and BottomTabNavigator display with increased height

I've been grappling with this issue for days now and haven't been able to find a solution. Any help is greatly appreciated. Whenever I reload the app, both the BottomTabBar and the Header experience an increase in height. Once the app has finishe ...

Having trouble setting up a page layout with CSS grid or grid-template-areas

Hey everyone, I'm a beginner in the world of HTML, CSS, and JS and this is my first time reaching out for help. I've been searching through various forums and spending quite some time on this particular issue, but unfortunately, I haven't fo ...

The background video on the website is having trouble resizing properly to fit the screen dimensions

I'm new to coding and I'm attempting to incorporate a background video on the homepage. The issue arises when I resize my window or view it on a mobile device, as the video fails to adjust to the window size, causing side scrolling that reveals t ...

Tips on how to pass properties as arguments to mixins

Here is the code I have: mox(first, second) {first} second a mox(transition, 0.3s linear all) I want to call the mixin like this: mox(transition 0.3s linear all) If we modify mox, it would look like this: mox() arguments a mox transition 0.3 ...