React.js white space - reactjs

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 :)

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!!

How to expand a Toggle upwards in react bootstrap?

I'm experimentating react bootstrap.
With the component Navbar.Collapse, to expand a NavDropdown upwards, i found this property drop="up"
<Navbar>
<Navbar.Toggle aria-controls="basic-navbar-nav"/>
<Navbar.Collapse id="responsive-navbar-nav">
<Nav>
<NavDropdown drop="up"
title="Changer la police"
id="basic-nav-nav"
onSelect={changeFont} >
<NavDropdown.Item
className={font.name}
eventKey={font.name}>
{font.name}
</NavDropdown.Item>
</NavDropdown>
</Nav>
</Navbar.Collapse>
</Navbar>
But i didn't find the equivalent for Navbar.Toggle, to as well expand upwards instead of downwards.
Thank you
I found a solution,
I added this code to the css :
.CustomFooter .navbar-collapse {
position: fixed;
bottom: 100px;
}
/* 1000px because this is the point where toggle disappears */
#media (min-width: 1000px) {
.CustomFooter .navbar-collapse {
position: relative;
bottom: 0px;
}
}
So it's get the impression of collapsing upwards

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;

Adding .png Logo to my Navigation bar with react styled components

hello I am trying to start a beginner react project using react and styled components. I was following a tutorial that showed me how to import some stock react logos, but I can't figure out how to do it using my own image.
export const NavbarContainer = styled(Container)`
display: flex;
justify-content: space-between;
height: 80px;
${Container}
`;
export const NavLogo = styled(Link)`
color: #fff;
justify-self: flex-start;
cursor: pointer;
text-decoration: none;
font-size: 2rem;
display: flex;
align-items: center;
`
export const NavIcon = styled(Icon)`
margin-right: 0.5rem;
`
Below is the code for my navigation bar
import React from 'react';
import { Nav, NavbarContainer, NavLogo, NavIcon } from './Navbar.elements';
import { ReactComponent as Icon } from './icon.png';
const Navbar = () => {
return (
<>
<Nav>
<NavbarContainer>
<NavLogo to="/">
<NavIcon />
SKYPRECISION
</NavLogo>
</NavbarContainer>
</Nav>
</>
)
}
export default Navbar
You need to add an img tag like this
<img src={src} alt="My awesome logo" />
You can replace the NavIcon with that.
If you want that image to utilize styled-components you can do something like:
const MyImage = styled.img`
your css rules here
`
and use it in code
<NavLogo to="/">
<MyImage />
SKYPRECISION
</NavLogo>

Next js font awesome and google fonts

Hoping to get some help on an issue I have been having in Next js. I am using Fontawesome-react package for icon imports which is working fine but when I attempt to load in a google font style sheet into the head of my main component, it changes the fonts but makes the font awesome icons disappear. I have tried a couple of different solutions such as loading the font locally and utilizing _document and _app components but none fix the issue I am having. Everything ends up changing the font but still gets rid of all the font awesome icons from every part of my app. I will copy in the Nav component I have and the Layout component that holds everything.
Thank you for any help!
import React from 'react'
import Nav from './nav/Nav'
import Head from 'next/head'
import Footer from './Footer'
type Props = {
title?: string
}
const Layout: React.FC<Props> = ({ children, title = 'Macros' }) => {
return (
<div>
<Head>
<title>{title}</title>
<link
href="https://fonts.googleapis.com/css?family=Darker+Grotesque&display=swap"
rel="stylesheet"
/>
</Head>
<Nav />
<div id="pageContent">{children}</div>
<Footer />
<style jsx global>{`
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
h1,
h2,
h3,
h4,
h5 {
font-weight: lighter;
font-family: 'Darker Grotesque', sans-serif;
}
#pageContent {
padding: 8rem 1rem;
}
`}</style>
</div>
)
}
export default Layout
import React, { useState } from 'react'
import { FontAwesomeIcon } from '#fortawesome/react-fontawesome'
import { faBars, faSearch, faPlus } from '#fortawesome/free-solid-svg-icons'
import Link from 'next/link'
const NavBar: React.FC = () => {
const [navBarStatus, isOpen] = useState<Boolean>(false)
const toggleMenu = () => {
isOpen(navBarStatus ? false : true)
}
return (
<nav id="navContainer">
<div id="mobileNav">
<ul id="navBarTop">
<li>
<button type="button" className="navIcon" onClick={toggleMenu}>
<FontAwesomeIcon icon={faBars} />
</button>
</li>
<li>
<Link href="/">
<a>
<h3>Macro</h3>
</a>
</Link>
</li>
<li>
<button type="button" className="navIcon">
<FontAwesomeIcon icon={faSearch} />
</button>
</li>
</ul>
<ul id="navbarBottom">
<li>Top</li>
<li>New</li>
<li>Protein</li>
<li>Carbs</li>
<li>Fats</li>
</ul>
</div>
<div id="appDrawer">
<ul id="topIcons">
<li>
<button type="button" className="navIcon" onClick={toggleMenu}>
<FontAwesomeIcon icon={faBars} />
</button>
</li>
<li>
<button type="button" className="navIcon">
<FontAwesomeIcon icon={faPlus} />
</button>
</li>
</ul>
<nav>
<ul id="menuList">
<Link href="/">
<a>
<p>Home</p>
</a>
</Link>
<Link href="/">
<a>Favorites</a>
</Link>
<Link href="/">
<a>Notifications</a>
</Link>
<Link href="/">
<a>Login/Sign up</a>
</Link>
</ul>
</nav>
</div>
<style jsx>{`
#navContainer {
background-color: #504761;
color: white;
position: fixed;
width: 100%;
}
#navContainer a {
text-decoration: none;
color: white;
}
#mobileNav {
display: ${navBarStatus ? 'none' : ''};
}
#navBarTop {
color: white;
display: flex;
justify-content: space-between;
list-style: none;
padding: 1rem 1rem 0.5rem 1rem;
font-size: 1.5rem;
}
.navIcon {
color: white;
border: none;
background-color: #504761;
font-size: 1.5rem;
}
#navbarBottom {
display: flex;
list-style: none;
justify-content: space-evenly;
padding: 1rem 0;
}
#appDrawer {
display: ${navBarStatus ? 'block' : 'none'};
background-color: #504761;
height: 100vh;
}
#topIcons {
display: flex;
justify-content: space-between;
list-style: none;
padding: 1rem;
font-size: 1.5rem;
}
#menuList {
padding: 2rem 0 2rem 1rem;
display: flex;
flex-direction: column;
}
#menuList a {
font-size: 2rem;
margin: 1rem 0;
}
`}</style>
</nav>
)
}
export default NavBar

Resources