Having difficulty incorporating CSS into my React project

**Hello everyone, I am currently attempting to incorporate CSS in React but am not seeing any changes on the app's home page. Additionally, I am interested in learning how to add pseudo selectors using MUI styled.**

This is the content of the CSS file:

lines {
    display: 'flex';
    flex-direction: row;
  }
  lines:before, lines:after{
    content: "";
    flex: 1 1;
    border-bottom: 1px solid;
    margin: auto;
  }
  lines:before {
    margin-right: 10px
  }
lines:after {
    margin-left: 10px
  }

And this is the home.js file :

import { styled } from '@mui/system';
import styles from './Style.css'; 

const MyComponent = styled('div')({
    backgroundImage : "url('https://images.pexels.com/photos/841130/pexels-photo-841130.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1')",
    height:'30vh',**strong text**
    backgroundPosition: "center",
        marginTop:'-80px',
        fontSize:'50px',
        backgroundSize: 'cover',
        marginRight : '-10px',
        marginLeft : '-10px',
        backgroundRepeat: 'no-repeat',
    textAlign : 'center',
    padding: 200,
    top: 200,

  });
  

const HomeComp = () => { 

return (
       <>
        <MyComponent>   </MyComponent> 
        <h4 className={styles.lines}> Home Page</h4>  
       </>  
)
}
export default HomeComp;

Answer №1

Consider importing your CSS in the following manner

import './Style.css';

Then, utilize it by referencing the class name directly

<h4 className="lines"> Homepage</h4>

Answer №2

Your imports have been successfully added, but when it comes to CSS, since they are classes, remember to include a . before them

.dividers {
  display: 'flex';
  flex-direction: row;
}

.dividers::before,
.dividers::after {
  content: "";
  flex: 1 1;
  border-bottom: 1px solid;
  margin: auto;
}

.dividers::before {
  margin-right: 10px
}

.dividers::after {
  margin-left: 10px
}

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

Ways to stop Angular from automatically scrolling to the center of the page

I am facing an issue with my angular 11 application. Whenever I navigate to a specific page, there is an automatic scroll down which I don't want. Please refer to the attachment (gif) and homepage.html below to understand the scenario. https://i.ssta ...

React-router: Issue with ProtectedRoute authentication mechanism not functioning as expected

I'm currently working on setting up protected routes that can only be accessed after the user has logged in. There are two main routes to consider: /login, which is the Login component (public), and /, which is the Dashboard component (protected). Wh ...

Submitting data through a PHP server-side script

I am facing a dilemma regarding why the form is not submitting and directing me to the index.php page. Being new to PHP, I am attempting to utilize the User object. Below is my current progress: <main> <header> <h1>Cr ...

Database SQL user identifier

I am working with two tables: user [id, username] comment [title, content, postid, userid] Using Node.js for my backend... is there a way to retrieve all comments without including the id, but instead have the usernames in the result? Select * from com ...

Sending a PDF generated with jsPDF to an API without the need for downloading it from the front end

I have been successful in generating a PDF on the front end and downloading it using the code below. However, I am now faced with the challenge of sending this generated PDF to the server via an API call using fetch or Axios. Despite my research efforts, ...

Error message: "nodeJS ejs link_to function is undefined"

I have encountered an issue with my code where I am receiving the error message "undefined is not a function". Upon inspection, it seems that the problem may be in the app.local section around 10 lines into app.js. As someone who is new to this and followi ...

Navigating through web pages in PHP

Is there a way to implement page navigation in PHP without reloading the entire page, similar to how Facebook operates, but without using jQuery or JavaScript? For example: For the welcome page: <a href="http://www.facebook.com/?sk=welcome"rel="nofoll ...

Switching text and updating form action on button press using jquery

My current issue is that the button on my form is only partially working. Initially, it displays 'add' and directs to the 'add.php' file, but upon clicking the button, the text does not change and the submission doesn't go to the & ...

Guide on setting up a sails.js application to listen on multiple ports at the same time

Take my sails.js application as an example, it is currently set to listen on port 1337 by default. I am interested in configuring it to simultaneously listen on two different ports - one for SSL traffic and one for non-SSL traffic. Can this setup be achiev ...

Issue encountered when trying to switch a foreign key to the actual name in a project utilizing

In my Game model, I have 2 foreign keys - away_team and home_team, both sourced from the Club model. When I retrieve data from the API to React.js, it looks like this: const AllGames = () => { //Simplified Game object const [games, setGames] = u ...

How to implement server-side rendering in Next.js 14 with GraphQL queries

I recently completed a Next.js project and configured Apollo Client. I integrated it with my components, as shown in my layout.tsx file: import { Inter } from "next/font/google"; import "./globals.css"; import ApolloProviderClient from ...

Searching for substrings that are an exact match, regardless of letter casing, in Node.js or C (no searching through entire texts

Which libraries offer efficient, case-insensitive exact substring matching in Node.js for a large dataset of strings? I am specifically interested in index-based solutions. For example, imagine a dataset comprising millions of strings: "Abc Gef gHi" "De ...

What are the steps to creating code that meets the high-quality standards of Themeforest

My plan is to sell bootstrap templates on the themeforest market but my first template got rejected. I believe the issue lies in the code structure and organization. Could you recommend any books or video courses that can help me write code that meets The ...

Comparing PHP and Node REST-API: Which is the better choice

Currently, I am in the process of developing a basic REST API with a single heavily used endpoint called POST /message. I am faced with the decision of whether to use Node.js or PHP for this project, with MySQL as the database. Within this route, the foll ...

Tips for adjusting the position of the second child in my navigation menu using CSS

Struggling with customizing my navigation menu in CSS, I'm seeking assistance. My goal is to have the second child element of the navigation menu on a new line instead of below the first child (refer to the image for clarification). An example of the ...

Conceal the button and reveal the hidden paragraph by clicking the button

I'm trying to create a button with dual functionality - when clicked, the button should disappear and a hidden p-tag (with display: none;) should become visible. <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis. ...

Setting up and using npm jshint with Grunt and Node.js

I have successfully installed node.js on Windows with the npm package. My project is located in the D drive at D:>projectD I am currently working on running jshint along with SASS, concat, etc. Everything seems to be working fine except for jshint ...

What is the best way to remove a logo from a wordpress website?

I've come across a theme that I find quite appealing, but the "designed by" logo is positioned in a rather bothersome place - right in the center of the page on the left side. Is there a way for me to remove it from there and relocate it to the footer ...

Tips for expanding the cell output width in Google Colab

After searching for a solution, I came across a similar question on Stack Overflow. However, the suggested fix didn't work on Google Colab. The issue is with the width of the text in my pandas dataframe columns, which currently defaults to 50%. from I ...

Trigger the callback function once the datatables DOM element has finished loading entirely

Hello there! I have a question regarding datatables. Is there any callback function available that is triggered after the datatables DOM element has finished loading? I am aware of the callbacks fnInitComplete, but they do not serve my purpose. Specificall ...