react-bootstrap flex/ justify-content is not working - reactjs

I'm doing instagram clonecoding with react, react-bootstrap, scss
Navbar was created, but it is not centered with flex box.
How can I solved this problem?
why flex center is not working?
And how do you typically customize in react-bootstrap?
Header.js
<Navbar className="navbarContainer align-items-center" fixed="top">
<div className="nav">
<Navbar.Brand href="/">
<img src={insta_logo} alt="instagram_logo" />
</Navbar.Brand>
<Form>
<FormControl
type="text"
placeholder="Search"
className="searchBar"
/>
</Form>
<Nav
navbar="false"
className="flex-row navRight"
>
<Nav.Link href="/">
<Home fontSize="24px" />
</Nav.Link>
<Nav.Link href="/message">
<Send fontSize="22px" />
</Nav.Link>
<Nav.Link href="/explore">
<Compass fontSize="24px" />
</Nav.Link>
<Nav.Link href="/favorite">
<Heart fontSize="24px" />
</Nav.Link>
<NavDropdown
title={
<Image
src={face}
roundedCircle
className="profileImg"
></Image>
}
drop="left"
>
<NavDropdown.Item href="#action/3.1" className="dropdownItem">
<Profile className="marginRight" />
<span>Profile</span>
</NavDropdown.Item>
<NavDropdown.Item href="#action/3.2" className="dropdownItem">
<Bookmark className="marginRight" />
<span>Bookmark</span>
</NavDropdown.Item>
<NavDropdown.Item href="#action/3.3" className="dropdownItem">
<Setting className="marginRight" />
<span>Setting</span>
</NavDropdown.Item>
<NavDropdown.Item href="#action/3.4" className="dropdownItem">
<Switch className="marginRight" />
<span>Switch Account</span>
</NavDropdown.Item>
<NavDropdown.Divider />
<NavDropdown.Item href="#action/3.4">Log Out</NavDropdown.Item>
</NavDropdown>
</Nav>
</div>
</Navbar>
header.scss
#mixin flex($justify: null, $align: null) {
display: flex;
justify-content: $justify;
align-items: $align;
}
.navbarContainer {
#include flex(center);
border-bottom: 1px solid #dbdbdb;
z-index: 200;
background-color: #fff;
.nav {
width: 940px;
display: flex;
justify-content: space-between;
align-items: center;
}
.searchBar {
height: 30px;
width: 220px;
background-color: #fafafa;
}
.navRight {
width: 225px;
display: flex;
justify-content: space-between;
}
.profileImg {
width: 25px;
height: 25px;
}
.dropdownItem {
#include flex(null, center);
.marginRight {
margin-right: 8px;
}
}
}
screen
enter image description here
I used a translator because I am not good at English. Please understand if the sentence is not good.
thank you

I found bootstrap class
Bootstrap can make layout using class.
https://getbootstrap.com/docs/4.0/utilities/flex/#enable-flex-behaviors
I modified the code
<Navbar
className="d-flex justify-content-center navbarContainer"
fixed="top"
>

Related

I’m building a portfolio but the sidebar component is not showing on any of the pages?

The sidebar is not showing on the home page of my portfolio or on any other pages like it’s supposed to be. Im wondering if it’s the CSS or something deeper. I assume the relevant code to this issue is of course the Sidebar component, App.js, and maybe Layout component and the scss file for the sidebar. Does anyone have any advice on how to narrow down as to which few files are likely the problem as it feels like it could be any of the components or their scss is not working together. Anyone know how to fix the sidebar not showing?
Sidebare index.js --->
import './index.scss'
import LogoS from '../../assets/images/logo-s.png'
import LogoSubtitle from '../../assets/images/logo_sub.png'
import { FontAwesomeIcon } from '#fortawesome/react-fontawesome'
import {
faLinkedin,
faGithub,
faYoutube,
faSkype,
} from '#fortawesome/free-brands-svg-icons'
import { faHome, faUser, faEnvelope, faSuitcase } from '#fortawesome/free-solid-svg-icons'
import { Link, NavLink } from 'react-router-dom'
const Sidebar = () => {
return (
<div className="nav-bar">
<Link className="logo" to="/">
<img src={LogoS} alt="Logo" />
<img className="sub-logo" src={LogoSubtitle} alt="slobodan" />
</Link>
<nav>
<NavLink exact="true" activeclassname="active" to="/">
<FontAwesomeIcon icon={faHome} color="#4d4d4e" />
</NavLink>
<NavLink activeclassname="active" className="about-link" to="/about">
<FontAwesomeIcon icon={faUser} color="#4d4d4e" />
</NavLink>
<NavLink activeclassname="active" className="portfolio-link" to="/portfolio">
<FontAwesomeIcon icon={faSuitcase} color="#4d4d4e" />
</NavLink>
<NavLink
activeclassname="active"
className="contact-link"
to="/contact"
>
<FontAwesomeIcon icon={faEnvelope} color="#4d4d4e" />
</NavLink>
</nav>
<ul>
<li>
<a
href="https://www.linkedin.com/in/slobodan-gaji%C4%87-006bb8b8/"
target="_blank"
rel="noreferrer"
>
<FontAwesomeIcon icon={faLinkedin} color="#4d4d4e" />
</a>
</li>
<li>
<a
href="https://github.com/bobangajicsm"
target="_blank"
rel="noreferrer"
>
<FontAwesomeIcon icon={faGithub} color="#4d4d4e" />
</a>
</li>
<li>
<a
href="https://www.youtube.com/channel/UCBu5ulO4d-d47lAVybpRTkw"
rel="noreferrer"
target="_blank"
>
<FontAwesomeIcon icon={faYoutube} color="#4d4d4e" />
</a>
</li>
<li>
<a href="skype:live:bobangajicsm" rel="noreferrer" target="_blank">
<FontAwesomeIcon icon={faSkype} color="#4d4d4e" />
</a>
</li>
</ul>
</div>
)
}
export default Sidebar
Sidebare scss -->
.nav-bar {
background: #181818;
width: 60px;
height: 100%;
position: absolute;
top: 0;
z-index: 3;
min-height: 500px;
.logo {
display: block;
padding: 8px 0;
img {
display: block;
margin: 8px auto;
width: 24px;
height: auto;
&.sub-logo {
width: 50px;
}
}
}
nav {
display: block;
text-align: center;
position: absolute;
height: 210px;
top: 50%;
margin-top: -120px;
width: 100%;
a {
font-size: 22px;
color: #4d4d4e;
display: block;
line-height: 51px;
height: 51px;
position: relative;
text-decoration: none;
i {
transition: all 0.3s ease-out;
}
&:hover {
color: #ffd700;
svg {
opacity: 0;
}
&:after {
opacity: 1;
}
}
&:after {
content: '';
font-size: 9px;
letter-spacing: 2px;
position: absolute;
bottom: 0;
display: block;
width: 100%;
text-align: center;
opacity: 0;
-webkit-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
&:first-child {
&:after {
content: 'HOME';
}
}
}
a.about-link {
&:after {
content: 'ABOUT';
}
}
a.contact-link {
&:after {
content: 'CONTACT';
}
}
a.portfolio-link {
&:after {
content: 'PORTFOLIO';
}
}
a.active {
svg {
color: #ffd700;
}
}
}
ul {
position: absolute;
bottom: 20px;
width: 100%;
display: block;
padding: 0;
list-style: none;
text-align: center;
margin: 0;
li {
a {
padding: 7px 0;
display: block;
font-size: 15px;
line-height: 16px;
color: #4d4d4e;
&:hover {
color: #ffd700;
}
}
}
}
}
App.js --->
import { Route, Routes } from 'react-router-dom'
import Home from './components/Home'
import About from './components/About'
import Contact from './components/Contact'
import Layout from './components/Layout'
import Portfolio from './components/Portfolio'
import Dashboard from './components/Dashboard'
import './App.scss'
function App() {
return (
<>
<Routes>
<Route path="/" element={<Layout />}>
<Route index element={<Home />} />
<Route path="about" element={<About />} />
<Route path="/contact" element={<Contact />} />
<Route path="/portfolio" element={<Portfolio />} />
<Route path="/dashboard" element={<Dashboard />} />
</Route>
</Routes>
</>
)
}
export default App
Layout index.js -->
import { Outlet } from 'react-router-dom'
import Sidebar from '../Sidebar/'
import './index.scss'
const Layout = () => {
return (
<div className="App">
<Sidebar />
<div className="page">
<span className="tags top-tags"><body></span>
<Outlet />
<span className="tags bottom-tags">
</body>
<br />
<span className="bottom-tag-html"></html></span>
</span>
</div>
</div>
)
}
export default Layout
Thank you in advance any help is greatly appreciated!!

Smoothening the header transition upon scroll in ReactJS static web application

I am new to React JS. Anyhow, I able to create the following Web App of my own.
My code works as I needed but with a small issue. The header shrinks and expands in a rugged manner (with a small vibration). The process does not happen smoothly. I suppose you can notice it in the gif image I provided above too. I need to make that transition smooth. How can I modify my code to achieve my aim?
This is the function I use to shrink the header upon scroll the page for 50 pixels down.
const [headerShrinked, setHeaderShrinked] = useState(false);
useEffect(() => {
function resizeHeaderOnScroll() {
const distanceY = window.pageYOffset || document.documentElement.scrollTop;
const shrinkOn = 50;
if (distanceY > shrinkOn) {
setHeaderShrinked(true);
} else {
setHeaderShrinked(false);
}
}
window.addEventListener("scroll", resizeHeaderOnScroll);
}, []);
And this is the external CSS code linked to it.
.header {
font-size: 55px;
font-weight: 600;
height: 70px;
letter-spacing: 1px;
padding-right: 40px;
padding-top: 0px;
}
.droplinks {
font-family: Arial;
font-size: 20px;
font-weight: 300;
color: black;
position: relative;
text-align: center;
}
.header {
height: 70px;
padding-right: 40px;
padding-top: 0px;
position: relative;
transition: height 0s linear 0.5s;
}
.header.shrinked {
height: 50px;
}
.headerBrand {
font-size: 40px;
font-weight: 600;
letter-spacing: 2px;
transition: font-size 0.5s;
}
.headerBrand.shrinked {
font-size: 30px;
}
.navlinks {
font-family: Arial;
font-size: 20px;
font-weight: 300;
letter-spacing: 2px;
padding-left: 30px;
padding-right: 30px;
position: relative;
text-align: center;
}
.navlinks:hover {
color: #ffffff;
text-shadow: 0px 0px 60px #ffffff;
transition: all 0.2s ease-in;
}
And here is the complete Js code.
import React, { useEffect, useState } from "react";
import { Navbar, Nav, NavDropdown } from "react-bootstrap";
import { Link } from 'react-router-dom';
import styles from "./Header.module.css";
const Header = (props) => {
const [headerShrinked, setHeaderShrinked] = useState(false);
useEffect(() => {
function resizeHeaderOnScroll() {
const distanceY = window.pageYOffset || document.documentElement.scrollTop;
const shrinkOn = 50;
if (distanceY > shrinkOn) {
setHeaderShrinked(true);
} else {
setHeaderShrinked(false);
}
}
window.addEventListener("scroll", resizeHeaderOnScroll);
}, []);
return (
<Navbar sticky="top" collapseOnSelect expand="lg" bg="dark" variant="dark">
<Navbar.Brand className={`${styles.headerBrand} ${headerShrinked ? styles.shrinked : ""}`}>
<Link to="/">
MyWebApp
</Link>
</Navbar.Brand>
<Navbar.Toggle aria-controls="responsive-navbar-nav" />
<Navbar.Collapse id="responsive-navbar-nav">
<Nav className="mr-auto">
<NavDropdown title="Get to Know Us" id="collasible-nav-dropdown" className={styles.navlinks}>
<div className={styles.dropboard}>
<NavDropdown.Item className={styles.droplinks}>
<Link to="ourstory">
Our Story
</Link>
</NavDropdown.Item>
<NavDropdown.Item className={styles.droplinks}>
<Link to="about">
About Us
</Link>
</NavDropdown.Item>
<NavDropdown.Divider/>
<NavDropdown.Item className={styles.droplinks}>
<Link to="newtrends">
New Trends
</Link>
</NavDropdown.Item>
</div>
</NavDropdown>
</Nav>
<Nav>
<Nav.Link className={styles.navlinks}>
<Link to="/">
Home
</Link>
</Nav.Link>
<Nav.Link className={styles.navlinks}>
<Link to="features">
Features
</Link>
</Nav.Link>
<Nav.Link className={styles.navlinks}>
<Link to="screenshots">
Screenshots
</Link>
</Nav.Link>
<Nav.Link className={styles.navlinks}>
<Link to="pricing">
Pricing
</Link>
</Nav.Link>
<Nav.Link className={styles.navlinks}>
<Link to="faqs">
FAQs
</Link>
</Nav.Link>
<Nav.Link className={styles.navlinks}>
<Link to="blog">
Blog
</Link>
</Nav.Link>
<Nav.Link eventKey={2} className={styles.navlinks}>
<Link to="contact">
Contact
</Link>
</Nav.Link>
</Nav>
</Navbar.Collapse>
</Navbar>
);
};
export default Header;

React.js white space

I'm having this issue that I can't solve. It appeared a white space between my first and second components, and I just can't understand where it came from. Nothing shows in the inspector. Here it is:
I'll leave a pic of my Navbar and Home components source code, so you can have a better look. I found the issue in the Navbar, without this ISSUE part, it cleans the top:
import React from "react";
import { Nav, Navbar } from "react-bootstrap";
const NavBar = () => {
return (
<React.Fragment>
<Navbar sticky="top" color="dark">
<Navbar.Brand href="#home">LOGO</Navbar.Brand>
<Nav className="mr-auto">
<Nav.Link href="#about">ABOUT</Nav.Link>
<Nav.Link href="#community">COMMUNITY</Nav.Link>
<Nav.Link href="#location">LOCATION</Nav.Link>
<Nav.Link href="#menu">OUR MENU</Nav.Link>
<Nav.Link href="#recipes">RECIPES</Nav.Link>
</Nav>
<Nav className="ml-auto">
<Nav.Link href="#contact">CONTACT</Nav.Link>
<Nav.Link href="#login">LOGIN</Nav.Link>
</Nav>
</Navbar>
//ISSUE
<Nav className="middle-navbar">
<Nav.Link href="#">One</Nav.Link>
<Nav.Link href="#info" className="ml-auto">
REQUEST INFO
</Nav.Link>
</Nav>
//ISSUE
</React.Fragment>
);
};
export default NavBar;
And the Home:
import React from "react";
import { Container } from "react-bootstrap";
const Home = () => {
return (
<Container fluid id="home-container">
<h1>THE BEST FOODIE</h1>
<h1 id="foddie-title">EXPERIENCE</h1>
<h6>NOW IN LONDON</h6>
</Container>
);
};
export default Home;
And SCSS:
#import "_mixins";
#font-face {
font-family: "din";
src: local("din"), url(../fonts/DIN.ttf) format("truetype");
}
* {
font-family: "din", sans-serif;
}
//NAVBAR
.middle-navbar {
position: relative;
top: 50vh;
}
//HOME
#home-container {
background: url("../img/bg-pic.png");
background-size: cover;
font-size: 100em;
height: 100vh;
color: white;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
Any help would be excellent :)

React bootstrap custom nav link active style is not working

Actually I want to make an active style of tab menu as hover style.
Even I tried with activeClassName="selected" not working. Can anyone help the issue which I am trying?
CSS which I am using
.my-navbar{
color: #037979;
font-size: 16px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
line-height: 1.6rem;
text-decoration: none;
margin: 10px 10px 10px 10px;
}
.my-navbar:visited {
font-family: Verdana, Geneva, Tahoma, sans-serif;
font-size: 16px;
}
.my-navbar:hover {
text-decoration: none;
font-family: Verdana, Geneva, Tahoma, sans-serif;
color: #c10944;
font-size: 16px;
background-color: #61dafb;
}
.active {
font-family: Verdana, Geneva, Tahoma, sans-serif;
color: #c10944;
font-size: 16px;
background-color: #61dafb;
}
react-bootstrap, react-router-dom these are the import using
<Router>
{/*header Menu Bar*/}
<div className="mycontainer">
<Navbar bg="transparent" expand="lg">
<Navbar.Brand>
<div>
<img src={logo} alt="logo" width="200" />
{/* <img src={process.env.PUBLIC_URL + "./images/logo.png"} alt="mypic" width="200" /> */}
</div>
</Navbar.Brand>
<Navbar.Toggle className="border-0" aria-controls="navbar-toggle" />
<Navbar.Collapse id="navbar-toggle" style={{marginTop: 30}}>
<Nav className="ml-auto" bsStyle="tabs" >
<Link activeClassName="selected" className="my-navbar" to="/">Home</Link>
<Link activeClassName="selected" className="my-navbar" to="/about">About</Link>
<Link className="my-navbar" to="/services">Services</Link>
<Link className="my-navbar" to="/contact">Contact</Link>
<Link className="my-navbar" to="/galleries">Galleries</Link>
</Nav>
</Navbar.Collapse>
</Navbar>
</div>
{/*Slider Bar*/}
<Slidingmain />
<div style={{ paddingTop: 50 }}>
<Route defaultActiveKey="/home" path="/" exact render={() => <HomePage title={this.state.home.title} subTitle={this.state.home.subTitle} text={this.state.home.text} />} className="container-full"/>
<Route path="/about" render={() => <AboutPage title={this.state.about.title} subTitle={this.state.about.subTitle} text={this.state.about.text} />} />
<Route path="/services" render={() => <ServicesPage title={this.state.services.title} />} />
<Route path="/contact" render={() => <ContactPage title={this.state.contact.title} />} />
<Route path="/galleries" render={() => <GalleriesPage title={this.state.galleries.title} />} />
<Footer />
</div>
</Router >
Please use <NavLink activeClassName="active"> instead of <Link activeClassName="selected">.
import { NavLink } from 'react-router';
For more information, visit https://reacttraining.com/react-router/web/api/NavLink
If using react-bootstrap Nav.Link you can use
defaultActiveKey like this:
<Nav defaultActiveKey="#home" className="mr-auto">
<Nav.Link href="#home">Home</Nav.Link>

How do I stop the css transition that happens when the page loads [React]

I am trying to make a transition when showing the side navigation and it works fine when opening and closing. The problem is when the page first loads the sidebar is shown withdrawning. Here is the code:
<div>
<span style={{ cursor: 'pointer' }} onClick={ this.showOrHideNav }>☰</span>
<Transition in={this.state.navStanje} timeout={ 500 }>
{ state =>
<div className={`navigacija navigacija-${state}`}>
<a to="javascript:void(0)" className="backButton" onClick={ this.showOrHideNav }><Typography variant="h7">×</Typography></a><br />
<div style={ profileDiv } >
<img src={require('../../images/campus.svg')} style={ imageStyle } height='100%'/><br />
<Typography style={ profileName }>Ime Prezime</Typography>
</div>
<div className="fadingLine"></div>
<Typography variant="h4" style={{ color: '#FFEB3B', marginTop: '3%' }}>Neki naslov</Typography>
<a to="#" className="linkovi">About</a><br />
<a to="#" className="linkovi">Services</a><br />
<a to="#" className="linkovi">Clients</a><br />
<a to="#" className="linkovi">Contact</a><br />
</div>
}
</Transition>
</div>
And here is the CSS I am using:
.navigacija {
position: fixed;
top: 8%;
left: 0;
height: 100%;
padding-top: 1%;
background: #2B3944;
width: 20%;
display: block;
overflow-x: hidden;
z-index: 2;
transition: all 0.5s linear;
}
.navigacija.navigacija-entering {
transform: translateX(0%);
}
.navigacija.navigacija-exited {
transform: translateX(-100%);
}
How can I prevent the withdrawing of the sidebar when the page loads?
Set the initial CSS transform property to transform: translateX(-100%); that way it will initially be hidden

Resources