Styling components in React

Asked

Viewed 248 times

0

I am starting my studies/development with React but I have a problem in the stylization of the components. Even though importing the CSS file into my component, the style is not picking up. How can I fix this??

import React from 'react';

import './styles.css';

const Header = () => (
  <header id="main-header">JShunt</header>

);

export default Header;
import React from  'react';

import './styles.css';

import Header from './components/Header';


const App = () => (
    <div className="App">
      <Header/>
      <p>Bricando com React</p>
    </div>
);

export default App;
header #main-header {
  width: 100%;
  height: 60px;
  background: #da552f;
  font-size: 18px;
  font-weight: bold;
  color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
}

inserir a descrição da imagem aqui

  • as Carlos put it as an answer, check if the Styles.css file is in your Components/Header .Looking at your code you can assume that there are two Styles.css files, one in the same App folder and the other in the Header folder

  • I edited the question by placing the directory screenshot. Yes, they are two styles: one of the componenente and the other is global

  • 1

    Change the declaration of your class to header#main-header { and voila, if you want, you can even keep #main-header

  • 1

    @Marceloboni. Perfect!! Had tried this way and was not there now yes. Anyway, thank you! Style applied

1 answer

0

shows your directory, the Header css in the same directory as the Header component?

missing put tbm the Return, left the correct example

import React from 'react';

import './styles.css';

const Header = () => {
  return (
    <header id="main-header">JShunt</header>
  )
}

export default Header;
  • 1

    Dude, when you omit the keys in an Arrow Function, you’re already returning the expression. You don’t need to Return in Eric’s case. Check out https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

  • I edited the question with a screenshot of the directory.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.