How to add custom css of react-bootsrap component in next js - css

i installed the react-bootstrap module using the pm command then imported it in my _app.js file now when i tried to change the bootstrap code i wasnt able to do so
my navbar component provided by bootstrap is this
import Image from 'next/image'
import {
Nav,
Navbar,
NavDropdown,
Form,
Button,
FormControl,
Container,
} from "react-bootstrap";
import headerStyles from '../styles/Header.module.css'
//${headerStyles.navLinks}
export default function NavBar() {
return (
<>
<Navbar bg="dark" expand="lg" variant="dark">
<Container fluid>
<Navbar.Brand href="#">
<Image src={'/logo.png'} height = "30px" width="190px"/>
</Navbar.Brand>
<Navbar.Toggle aria-controls="navbarScroll" />
<Navbar.Collapse id="navbarScroll">
<Nav
className={"me-auto my-2 my-lg-0 " + headerStyles.navLinks}
style={{ maxHeight: "100px" }}
navbarScroll
>
<Nav.Link className={headerStyles.navLinks_l} href="#action1">Home</Nav.Link>
<Nav.Link href="#action2">Link</Nav.Link>
<Nav.Link href="#action2">Link</Nav.Link>
<Nav.Link href="#" disabled>
Link
</Nav.Link>
</Nav>
<Form className="d-flex">
<FormControl
type="search"
placeholder="Search"
className={"me-2"}
aria-label="Search"
/>
</Form>
</Navbar.Collapse>
</Container>
</Navbar>
</>
);
}
here I want to try to customize the CSS of bootstrap which I tried doing with CSS module but I failed. Then I used a global stylesheet to do so but failed
can someone please help me with this?
global css:
.navbar-collapse{
background-color: aqua;
color: black;
}
.navbar-dark .navbar-nav .nav-link {
color: rgb(0, 0, 0);
background-color: blue;
}
.navbar-expand-lg .navbar-nav{
justify-content: space-around;
margin: 0px;
}
.me-auto{
margin: 0 !important;
}

Import global.css after importing bootstrap in _app.js
import "bootstrap.min.js"
import "global.css"
using !important is not a good choice. explanation here

Related

Can't get Bootstrap Scrollspy working on React

Hi I'm trying to get scrollspy working on React using Bootstrap but I seem to struggle to make it work.
I have tried several ways to do this but I really have no idea how to make this work and it'll be much appreciate if you can help me with this...
This is the css
body {
margin: 0;
font-family: "Roboto", sans-serif !important;
scroll-behavior: smooth;
overflow-x: hidden;
position: relative;
height: 100%;
}
This is body in index.html
body
data-bs-spy="scroll"
data-bs-target="#navbar-menu"
data-bs-offset="0"
class="scrollspy-example"
tabindex="0"
This is in Navbar component and inside Menu component I'm assigning the hrefs
<Navbar
id="navbar-menu"
className="py-2 py-md-0 bg-white"
expand="lg"
sticky="top"
>
<Container>
<NavbarBrand classes="" />
<Navbar.Toggle aria-controls="basic-navbar-nav" className="border-0" />
<Navbar.Collapse id="basic-navbar-nav" className="justify-content-end">
<Menus classes="top-nav px-3 mx-2 px-md-2 py-md-4 mx-md-1 mb-3 mb-md-0" />
</Navbar.Collapse>
</Container>
</Navbar>
Inside Menu
<Nav className="flex-wrap flex-lg-nowrap me-3">
{navMenu.map((menu, index) => (
<Nav.Link
href={menu.href}
key={menu.href}
>
{menu.name}
</Nav.Link>
))}
</Nav>
I have Landing component that hold everything and inside each wrapper there's id name as same as the nav menu
const Landing = () => {
return (
<>
<NavbarMenu />
<HeroWrapper />
<AboutWrapper />
<EcosystemWrapper />
<TokenomicsWrapper />
<TeamWrapper />
<FooterNav />
</>
);
};
export default Landing;

How to change the bootstrap navbar toggler in React

In React I want to either change the toggler completely or at least change the color. I've tried the solutions on the below links with no luck.
5 Years Ago
1 Year Ago
1 Month Ago
I can see the code in the dev tools but it's crossed out, does this mean it's being overidden by Bootstrap?
Here is my NavBar.js file:
import React, { Component } from "react";
import logo from "../images/logo.png";
import { Nav, Navbar, NavDropdown, Form, FormControl, Button, Container } from "react-bootstrap"
import 'bootstrap/dist/css/bootstrap.min.css';
export default class NewNav extends Component {
render() {
return <div className="myContainer">
<Navbar id="navbar" className="newNav" expand="lg">
<Navbar.Brand href="/"><img id="logo" src={logo} alt="Company Name"/></Navbar.Brand>
<Navbar.Toggle className="custom-toggler" aria-controls="basic-navbar-nav" />
<Navbar.Collapse id="basic-navbar-nav">
<Nav className="ml-auto">
<Nav.Link id="nav-links" href="/cleaning-services">Services</Nav.Link>
<Nav.Link href="#link">About</Nav.Link>
<Nav.Link href="#link">Something Else</Nav.Link>
<Nav.Link href="#link">One more then</Nav.Link>
</Nav>
</Navbar.Collapse>
</Navbar>
</div>
}
}
This is my CSS for the custom-toggler in <Navbar.Toggle
.navbar-light .navbar-toggler-icon {
background-image: url("https://cdn4.iconfinder.com/data/icons/ionicons/512/icon-ios7-bell-512.png");
}
Any help would be appreciated
In the end I decided to create my own image using Canva and reference the image in the CSS URL and add the !important tag. Details are below is anyone stumbles across this.
.navbar-light .navbar-toggler-icon {
background-image: url("../src/images/alignRight.svg") !important;
border-color: var(--secondaryColor) !important;
}
I also changed the border to transparent to get my final button as seen below.

Style not being applied correctly to Navbar React component

I'm learning Next.js — currently on version 10.0.3. I'm using react-bootstrap version 1.4.0 and classnames version 2.2.6.
I'm using one component (Navbar) that I'm trying to apply certain styles to, but so far it isn't working. This is what I have so far:
// ~/project-name/components/Header.tsx
import classnames from "classnames";
import Link from "next/link";
import React from "react";
import { Container, Nav, Navbar } from "react-bootstrap";
import styles from "./Header.module.css";
const Header: React.FC = () => {
return (
<>
<Navbar className={classnames(styles.borderBottom, styles.boxShadow)} bg="dark" expand="lg" variant="dark">
<Container>
<Link href="/" passHref>
<Navbar.Brand><span className="font-weight-bold">./shīdo.io</span></Navbar.Brand>
</Link>
<Navbar.Toggle aria-controls="id-navbar-nav" />
<Navbar.Collapse id="id-navbar-nav">
<Nav className="ml-5 mr-auto">
<Link href="/" passHref>
<Nav.Link active>Home</Nav.Link>
</Link>
<Link href="/features" passHref>
<Nav.Link>Features</Nav.Link>
</Link>
</Nav>
<Nav>
<Link href="/login" passHref>
<Nav.Link>Login</Nav.Link>
</Link>
</Nav>
</Navbar.Collapse>
</Container>
</Navbar>
</>
);
};
export default Header;
# ~/project-name/components/Header.module.css
#charset "UTF-8";
.border-bottom {
border-bottom: 5px solid #e5e5e5;
}
.box-shadow {
box-shadow: 0 .5rem .75rem rgba(0, 0, 0, .05);
}
The issue is that border-bottom and box-shadow are not being applied to the resulting nav HTML tag in the final document. Any help will be appreciated.
I've also tried to use <style jsx>{``}</style> (with the same styles) within the same Header.tsx component, but it doesn't do anything either.
CSS class names are not picking up. you may try giving like below:
className={classnames(styles['border-bottom'], styles['box-shadow'])}>
React updates the provided user stylesheet class names with their updated names if seen in the developer console.
Not sure if that answers your doubt but you can try something like this for selecting that element through class name:
[class^="Header_border-bottom"] or [class*="Header_border-bottom"]

How do I align react-router NavLink in the bootstrap Navbar?

I want to use NavLink instead of Nav.Link in my react-bootstrap navbar so I can use the activeClassName prop. However it seems that all the links lose their alignment, there is no longer any horizontal margin between them and they are not centered vertically in the navbar:
code as follows:
function NavbarDefault() {
return (
<Container>
<Navbar variant="custom" expand="md">
<Navbar.Brand as={NavLink} to="/">
<img
className="navbar-logo-image"
src={logo} alt="Brand Logo" />
<span className="navbar-logo-text">cool brand</span>
</Navbar.Brand>
<Navbar.Toggle
className="navbar-toggler-custom"
aria-controls="basic-navbar-nav" />
<Navbar.Collapse id="basic-navbar-nav">
<Nav className="ml-auto">
<NavLink className="nav-link-custom" activeClassName="nav-link-custom-active" to="/features">Features</NavLink>
<NavLink className="nav-link-custom" activeClassName="nav-link-custom-active" to="/pricing">Pricing</NavLink>
<NavLink className="nav-link-custom" activeClassName="nav-link-custom-active" to="/contact">Contact</NavLink>
<SecondaryButton
className="navbar-login-button">
Try now
</SecondaryButton>
</Nav>
</Navbar.Collapse>
</Navbar>
</Container>
);
}
and CSS:
.nav-link-custom {
color: #41a2fb;
}
.nav-link-custom:hover {
color: #0681EF;
text-decoration: none;
}
.nav-link-custom-active {
color: red;
}
Originally I tried to solve this problem by using something like <Nav.Link as={NavLink} ....... this worked for the navigation and alignment however the activeClassName prop doesn't work that way, so I had to revert to NavLink. How can I center these nav links vertically in the navbar?

Having trouble to use justify-content: space-between; in react-bootstrap

My problem is that justify-content: space-between seems doesnt work in my code.
import React from 'react';
import {Button, Navbar, Nav, NavDropdown} from 'react-bootstrap';
import '../styles/headerStyle.scss';
const Header = () => (
<React.Fragment>
<Navbar collapseOnSelect expand='lg' bg='dark' variant='dark'>
<Navbar.Brand href='#home'>React-Bootstrap</Navbar.Brand>
<Navbar.Toggle aria-controls='responsive-navbar-nav' />
<Navbar.Collapse id='responsive-navbar-nav'>
<Nav>
<div className='container'>
<Nav.Link>Features</Nav.Link>
<Nav.Link>Pricing</Nav.Link>
<NavDropdown title='Dropdown' id='collasible-nav-dropdown'>
<NavDropdown.Item href='#action/3.1'>Action</NavDropdown.Item>
<NavDropdown.Item href='#action/3.2'>
Another action
</NavDropdown.Item>
<NavDropdown.Item href='#action/3.3'>Something</NavDropdown.Item>
<NavDropdown.Divider />
<NavDropdown.Item href='#action/3.4'>
Separated link
</NavDropdown.Item>
</NavDropdown>
<Nav.Link>More deets</Nav.Link>
<Nav.Link eventKey={2} href='#memes'>
Dank memes
</Nav.Link>
</div>
</Nav>
</Navbar.Collapse>
</Navbar>
</React.Fragment>
);
export default Header;
Here is stylesheet:
.container {
padding: 0;
margin: 0;
display: flex;
justify-content: space-between;
}
Here is my current result:
current header
Here is the tutorial I follow, I am not sure where do I make mistakes in my code. Thanks in advance for any help!

Resources