The styles in the CSS file are not behaving as expected

Having an issue with my CSS file for the Header.js module. Despite writing rules, only one style is applying. Can anyone help me identify the problem? Thanks in advance!

Header.js component

import React from 'react';
import '../../../asset/css/updated/header.module.css'

const Header = () => {
    return (
        <div className='header-container'>
            <h1 className='header-title'>Some text here</h1>
            <svg width="130%" height="100%" id="svg" viewBox="0 0 1440 690" xmlns="http://www.w3.org/2000/svg" class="transition duration-300 ease-in-out delay-150"><defs><linearGradient id="gradient" x1="0%" y1="50%" x2="100%" y2="50%"><stop offset="5%" stop-color="#56b5e3"></stop><stop offset="95%" stop-color="#7d58a5"></stop></linearGradient></defs><path d="M 0,700 C 0,700 0,350 0,350 C 136.8,427.20000000000005 273.6,504.40000000000003 456,480 C 638.4,455.59999999999997 866.4000000000001,329.6 1038,291 C 1209.6,252.4 1324.8,301.2 1440,350 C 1440,350 1440,700 1440,700 Z" stroke="none" stroke-width="0" fill="url(#gradient)" fill-opacity=".9" class="transition-all duration-300 ease-in-out delay-150 path-0" transform="rotate(-180 720 350)"></path></svg>
        </div>
    );
};

export default Header;

header.module.css file

path{
    fill:url(#gradient) !important;
}
.header-container{
    position: relative;
}
.header-title{
    position: absolute;
    color: white;
    margin-top: 10px;
    margin-left: 10px;
}

Answer №1

It's recommended to import and utilize your CSS module stylesheet in the following manner:

import React from 'react';
import style from '../../../asset/css/updated/header.module.css'

const Header = () => {
    return (
        <div className={style.header-container}>
            <h1 className={style.header-title}>Insert text here</h1>
            ...
        </div>
    );
};

export default Header;

Answer №2

It's important to note how you can import CSS files in your project. You have two options:

import '../../../asset/css/updated/header.css'

If you choose not to use modules, or

import css from '../../../asset/css/updated/header.module.css';

If you want to use CSS modules. Afterwards, you can utilize it in your code like this:

<div className={css.header-container}>
  <h1 className={css.header-title}>Some text here</h1>
  <svg></svg>
</div>

Answer №3

As stated in the official documentation for React, it is recommended to utilize header.module.css styles within curly braces. Therefore, the CSS file should be imported as

import styles from './header.module.css';
and the class should be used as className={style.header-container}

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

Using REST APIs in React programming

While working on an existing code base for a React application, I found myself in a situation where the original developer had left and I am still quite new to React. In the current code base, the library "request-promise-native" is being passed from one c ...

I'm puzzled as to why the hidden input field consistently returns the same value every time

As a beginner in php, I am facing an issue where I cannot trace the correct value of the hidden input which represents the ID of the image in the products table. Every time I try to delete an image, it always returns the ID of the last image in the product ...

Issue with react-quill image handler failing to display images

import ReactQuill from "react-quill"; import Quill from "quill"; import "react-quill/dist/quill.snow.css"; const AddPrice = () => { const quillRef = useRef(null); const [body, setBody] = useState(""); const too ...

Sloped Divider on the Upper Edge of the Page

I'm currently in the process of developing a new website, and I'm looking to create a unique design for the main navigation bar on the homepage. Here is the ideal layout that I have in mind: https://i.stack.imgur.com/pc8z4.png While I understan ...

Issues with JQuery OnClick Function Detected

I am struggling with an issue related to the scripts in the <head> section of my website: <script src="scripts/jquery-1.11.0.min.js" type="text/javascript"></script> <script> $('#submit').click(function() { $('#submi ...

Adjusting the image width to a set height requirement

When working with images, it can be tricky to maintain the aspect ratio. For example, if you have an image set to a specific height like 500px within a div that is 960px wide, the image may stretch to fill the width. This can distort the image and give ver ...

How to horizontally center an element using HTML and CSS

I am encountering an issue while trying to create a navigation bar or header. The problem lies in centering an h1 element. Here is the HTML code I am using: body { margin: 0; padding: 0; } header { display: flex; justify-content: space-between; ...

Implementing a Standardized Template for Consistent Design and styling Throughout Website

As I work on building my website, I find myself struggling with some of the intricacies. The homepage is set up with a navbar and header, along with several pages that can be easily navigated to. While everything seems to be functioning properly, upon ins ...

Setting the InfoBox element to appear behind the Marker in a React Google Maps application

Issue - I am currently utilizing react-google-maps and have multiple markers with onClick functions to display specific infoboxes. Despite setting the pane of the infobox to 'mapPane' in order to position it behind the marker, it still appears ov ...

discovering obscured information using jquery

I am working on a code snippet where I need to hide the detailed content for display purposes and only show it during printing: <div> <ul> <li> <span style="font-size: 1.25em;"> <strong> ...

Ways to conceal the TippyJS tooltip so it doesn't show up on video embeds

My website has tooltips enabled, but I am looking to hide the tooltip pop-ups that appear specifically over youtube video embeds. Upon inspecting the webpage, I found the code snippet below that is associated with youtube videos: <div data-tippy-root id ...

Tips on passing an array retrieved from another query as a parameter in a database call using Firebase

Looking for help with creating a compound query in Expo React Native with Firestore. I have two collections in Firebase: one for user IDs ("node") and the other for IDs of places discovered by the user. I want to take this array of place IDs and use them a ...

The issue of React-select not displaying the value persists in Laravel-mix

A team of students from a school has delivered a frontend application using React, and now we need to create a backend for it using Laravel. Everything is functioning correctly except for one issue: the dropdown menu does not display the selected value in ...

Guide to resolving react-native issue post updating expo to version 50.0

Upon executing npm run ios in the terminal, I encountered the following error message: Error: node_modules/expo-router/entry.js: [BABEL]: expo-router/babel is no longer supported and has been replaced by babel-preset-expo in SDK 50 In an attempt to reso ...

Having trouble downloading a PDF file on a local server with React and the anchor tag element

Having trouble downloading a pdf file from my react app to my Desktop. I've reached out for help with the details How to download pdf file with React. Received an answer, but still struggling to implement it. If anyone new could provide insight, that ...

The table's width exceeds the appropriate size

Take a look at the code snippet below <%-- Document : index Created on : Feb 7, 2014, 1:03:15 PM --%> <%@page import="java.util.Map"%> <%@page import="java.util.Iterator"%> <%@page import="analyzer.DataHolder"%> <%@p ...

Leveraging HTML div elements for forms can greatly enhance the user

I am in the process of developing a website where users can upload images, name them, and then submit the data to PHP code. Currently, I am using plain HTML and PHP for this project, but I intend to integrate the Bulma CSS library. The current HTML code l ...

What is the best method for showing information beneath each tab?

Here is my CodePen link: https://codepen.io/santoshch/pen/MWpYdXK .tab1border{ border-right: 2px solid #f0f0f0; } .tab2border{ border-right: 2px solid #f0f0f0; } .tab3border{ border-right: 2px solid #f0f0f0; } .tab4border{ border-right: 2px soli ...

During the installation process of Next JS, I faced a challenge that hindered

While setting up NextJS, I ran into the following issue: D:\Codes\React\Learn>npx create-next-app npm WARN using --force Recommended protections disabled. npm WARN using --force Recommended protections disabled. npm ERR! code E404 npm ERR ...

New feature in Bootstrap 4 beta allows carousel arrows to be positioned outside of the

I created a text-based carousel using Bootstrap 4 beta. Is it possible to move the arrows off of the slider area and position them outside of it? I have tried searching on Google and in other forums, but I couldn't find a solution. The issue is that s ...