1

Why is my custom css styles not working with react-bootstrap? I use npx create-react-app, node-sass and npm i react-bootstrap. What Am i missing?

Thanks!

Here is my sample files:

file structure

index.js code:

import "bootstrap/dist/css/bootstrap.min.css";



/*import here*/

ReactDOM.render(
  <BrowserRouter>
    <App />
  </BrowserRouter>,
  document.getElementById("root")
);

custom scss

 body {
  background: #0b739c;
}

.login-form {
  background: white;

  h1 {
    /*styles here*/
  }

  form {
    input {
      background: #ffffff;
      border: 1px solid #dcdcdc;
      box-sizing: border-box;
      border-radius: 40px;
    }
  }
}

login.js code

import "./Login.module.scss";
/*code here*/

    const Login = () => {
      return (
        <Container fluid>
          <Row>
            <Col>
              <Image src={LoginImage} alt="login image" />
              <h2>Bring all your friends to any network!</h2>
            </Col>
            <Col className="m-0 login-form">
              /*form code here*/
            </Col>
          </Row>
        </Container>
      );
    };
    
    export default Login;

Sample output, custom styles not reflecting:

Form UI

2 Answers 2

1

It basically boils down to the following steps:

Download bootstrap using npm install react-bootstrap

  1. Install SASS pre-processor (https://sass-lang.com/install)

  2. Create a scss file for overriding bootstrap's _variables.scss (make sure the path to _functions.scss, _variables.scss, _mixins.scss and bootstrap.scss is correct

    @import "bootstrap/scss/functions"; 
    @import "bootstrap/scss/variables";
    @import "bootstrap/scss/mixins";
    
    /* Your customizations here */
    
    $theme-colors: (
      primary: red;
     );
    
    @import "bootstrap";
    
  3. Transpile your stylesheet.scss to stylesheet.css and add a reference to your head section like so: https://uxplanet.org/how-to-customize-bootstrap-b8078a011203

Sign up to request clarification or add additional context in comments.

Comments

0

I solve the issue instead on Login.module.scss, change to the file to Login.scss and it works fine.

Thank you

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.