I am new to both React and Boostrap, so I have started playing with them using react-bootstrap
. I heard that one of the simplest ways to override a boostrap CSS was to apply your own CSS on top of bootstrap CSS. So I have the following page
I have the following App.js
import React from 'react';
import Nav from 'react-bootstrap/Nav';
import Navbar from 'react-bootstrap/Navbar';
import Container from 'react-bootstrap/Container';
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';
import "bootstrap/dist/css/bootstrap.css";
import './App.css';
import { BrowserRouter as Router, Switch, Route, Link } from 'react-router-dom';
function App() {
return (
<Router>
<Container fluid>
<Navbar bg="dark" expand="lg" id="navbar-parent">
<Navbar.Brand href="#home" id="navigation-bar">TURLS</Navbar.Brand>
<Navbar.Toggle aria-controls="basic-navbar-nav"/>
<Navbar.Collapse id="basic-navbar-nav">
<Nav className="mr-auto" variant="pills">
<Nav.Link href="#home" className="whte">Home</Nav.Link>
<Nav.Link href="#api" className="whte">API</Nav.Link>
</Nav>
</Navbar.Collapse>
</Navbar>
</Container>
</Router>
);
}
export default App;
Following is the App.css
#navigation-bar {
border-style: solid;
padding: 15px;
border-radius: 50px;
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
font-weight: 900;
color: white;
border-width: 5px;
font-size: 1.5em;
}
#navigation-bar:hover {
color: #3399ff;
}
.whte {
color: white;
}
I was able to override Nav.Brand
's font and color using my own CSS and referencing it using CSS #id
selector. But I wasn't able to override the Nav.Link
's using a custom CSS class .whte
. I was trying to override the color of Home and API, wanted to change the font, the pills
size and background color, but I don't know how.
I can change the color of the text using !important
, but I read somewhere that using that was not a nice way to customize things. Upon inspecting elements, I found out that the Nav.Links
were getting their color from the following CSS classes despite my custom class .whte
.navbar-light .navbar-nav .nav-link {
color: rgba(0,0,0,.5);
}
Similarly I found out that the blue colored nav-pills
were actually part of the following classes
.navbar-light .navbar-nav .active>.nav-link, .navbar-light .navbar-nav .nav-link.active, .navbar-light .navbar-nav .nav-link.show, .navbar-light .navbar-nav .show>.nav-link {
color: rgba(0,0,0,.9);
}
and
.nav-pills .nav-link.active, .nav-pills .show>.nav-link {
color: #fff;
background-color: #007bff;
}
I am not sure what classes to customize for my desired effects to take place. I have tried adding my own CSS implementation, but that doesn't work.
So how does one usually go about customizing bootstrap css? Should I override all the CSS classes a boostrap element is associated with? Or should I put an ID on every elements and customize each of them separately with the same code.
My apologies if the question is too naive or ambiguous, I am just trying to understand the recommended way to change or customize a bootstrap CSS in React Bootstrap
Thanks for your help