footer page end distance - reactjs

I added a footer to my page. When it is a page length it covers the content.
There should be a distance between the end of the page and the footer.
It's ok when the page is 100 percent, but it happens when the page gets longer
But I want a distance between.This is scss.
.footer {
display: flex;
background-color: #222831;
min-height: 5vh;
justify-content: space-between;
padding: 10px;
align-items: center;
position: fixed;
left: 0;
bottom: 0;
width: 100%;
This is my layout
import React from "react";
import Footer from "./footer";
import Header from "./header";
const Layout = ({ children }) => {
return (
<div className="layout">
<Header />
<div className="children">{children}</div>
<Footer></Footer>
</div>
);
};
export default Layout;
This is my footer
import {
AiFillLinkedin,
AiFillGithub,
AiFillInstagram,
AiOutlineMail,
} from "react-icons/ai";
export default function Footer() {
return (
<div className="footer">
<div className="logo">
<span className="bracket">{"<"}</span>
<p>Handcrafted by</p>
<span className="bracket">{"{"}</span>
<span className="name">{"ömer"}</span>
<span className="bracket">{"}"}</span>
<span className="bracket">{"/>"}</span>
</div>
<div className="icons">
<a href="https://www.linkedin.com/in/omersahin1/">
<AiFillLinkedin className="icon" size={20} />
</a>
<a href="https://github.com/1sahinomer1">
<AiFillGithub className="icon" size={20} />
</a>
<a href="https://github.com/shnomr">
<AiFillInstagram className="icon" size={20} />
</a>
<a href="mailto:1sahinomer1#gmail.com">
<AiOutlineMail className="icon" size={20} />
</a>
</div>
</div>
);
}
Thank you.

Related

react-responsive-carousel is not displaying images/ not working

import "react-responsive-carousel/lib/styles/carousel.min.css";
import { Carousel } from "react-responsive-carousel";
function App() {
return (
<Carousel showArrows={true}>
<div>
<img src="../assets/1.jpeg" alt="image1" />
<p className="legend">Legend 1</p>
</div>
<div>
<img src="../assets/2.jpeg" alt="image2" />
<p className="legend">Legend 2</p>
</div>
<div>
<img src="../assets/3.jpeg" alt="image3" />
<p className="legend">Legend 3</p>
</div>
</Carousel>
);
}
export default App;
i added the css file in App component similar like react-responsive-carousel but it is not working
carousel.min.css
import "react-responsive-carousel/lib/styles/carousel.min.css";
import { Carousel } from "react-responsive-carousel";
It should be working but not sure why this is happening
I don't know about this library, But I can see you are not doing something complicated with your carousel. So basically why don't you create one for yourself?
I have a base code that could help you in this matter.
I create a carousel with React and Static UI(HTML, CSS, JS).
I think it can actually help you out.
replit, codesandbox, Stackblitz
these versions are written with html css js and nothing else.
replit, codesandbox, Stackblitz
In your scenario I will do this:
const modalSlidesContainer = document.querySelector(".modal-slides-container");
const modalWidth = 300;
let modalPage = 0;
const nextPage = () => {
modalPage++;
modalSlidesContainer.style.margin = `0px 0px 0px -${modalWidth * modalPage}px`;
};
const previousPage = () => {
modalPage--;
modalSlidesContainer.style.margin = `0px 0px 0px -${modalWidth * modalPage}px`;
};
/* you set root to define varibales */
:root {
--modal-width: 300px;
--modal-height: 400px;
--number-of-pages: 5;
}
html body{
margin: 0px;
}
.modal-background{
background-color: rgba(0,0,0,0.4);
position: absolute;
top: 0;
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
z-index: 0;
}
.modal-boundary{
width: var(--modal-width); /* the width boundary must be as same as every modal slide*/
height: var(--modal-height);
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;
overflow-x: hidden;
z-index: 10;
/* the max width must be as same as the width of modal ModalBoundary*/
#media screen and (max-width: var(--modal-width)) {
width: 100vw;
height: 100vh;
}
}
/* This container contains every slide you gonna use in your modal */
.modal-slides-container{
min-width: calc(var(--modal-width) * var(--number-of-pages)); /* The width must be total width of all the slide you gonna use */
height: var(--modal-height);
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;
background-color: white !important;
/*here is how to control carousel movement*/
margin: 0px; /*this how we control the place of the modal*/
transition: margin 1s; /*this how you control the animation of carousel when it's changing steps */
}
.modal-slide{
width: var(--modal-width);
height: var(--modal-height); /* in this scenario the total height of slide must be as same as modal height*/
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: white !important;
}
.button-container{
width: 100%;
margin-top: 10px;
display: flex;
flex-direction: row;
}
.navigation-button{
margin: auto;
}
<body>
<div class="modal-background">
<div class="modal-boundary">
<div class="modal-slides-container">
<div class="modal-slide">
<img alt="first image" src="https://picsum.photos/200/200" />
<p> Legend One </p>
<div class="button-container">
<button onclick="nextPage()" class="navigation-button">
next
</button>
</div>
</div>
<div class="modal-slide">
<img alt="second image" src="https://picsum.photos/200/200" />
<p> Legend Two </p>
<div class="button-container">
<button onclick="previousPage()" class="navigation-button">
previous
</button>
<button onclick="nextPage()" class="navigation-button">
next
</button>
</div>
</div>
<div class="modal-slide">
<img alt="third image" src="https://picsum.photos/200/200" />
<p> Legend Three </p>
<div class="button-container">
<button onclick="previousPage()" class="navigation-button">
previous
</button>
<button onclick="nextPage()" class="navigation-button">
next
</button>
</div>
</div>
<div class="modal-slide">
<img alt="fourth image" src="https://picsum.photos/200/200" />
<p> Legend Four </p>
<div class="button-container">
<button onclick="previousPage()" class="navigation-button">
previous
</button>
<button onclick="nextPage()" class="navigation-button">
next
</button>
</div>
</div>
<div class="modal-slide">
<img alt="fifth image" src="https://picsum.photos/200/200" />
<p> Legend five </p>
<div class="button-container">
<button onclick="previousPage()" class="navigation-button">
previous
</button>
</div>
</div>
</div>
</div>
</div>
</body>
I hope this helps you.^-^

Swiperjs isn't working with my css grid on nextjs

I'm trying to do an about page and i need 3 sets of elements inside a vertical slider, so i picked swiperjs. Without the carousel, they were working just fine as far as the grid goes, but now the columns are extremely tall and the elements aren't in their correct rows. Here's how it looks on the jsx
<container className = {styles.sobreGeral}>
<div className={styles.parent}>
<Swiper
direction={"vertical"}
pagination={{clickable: true,}}
modules={[Pagination]}
>
<SwiperSlide>
<div className={styles.div1}>
<img src="sobre.jpg" alt="alt" className={styles.imagem} />
</div>
<div className={styles.div2}>
<img src="logo-sobre.jpg" alt="logo" className={styles.imagem} />
</div>
<div className={styles.div3}>
<p>text</p>
</div>
</SwiperSlide>
<SwiperSlide>
<div className={styles.div1}>
<img src="sobre-rita.jpg" alt="pic" className={styles.imagem} />
</div>
<div className={styles.div2}>
<h2>Rita </h2>
</div>
<div className={styles.div3}>
<p>text</p>
</div>
</SwiperSlide>
<SwiperSlide>
<div className={styles.div1}>
<img src="sobre-jose.jpg" alt="pic" className={styles.imagem} />
</div>
<div className={styles.div2}>
<h2>Jose </h2>
</div>
<div className={styles.div3}>
<p>text</p>
</div>
</SwiperSlide>
</Swiper>
</div>
</container>
}
and here's how the css is setup
.sobreGeral{
display: flex;
margin-top: 150px;
}
.contato{
display: flex;
justify-content: center;
}
.parent {
display: grid;
grid-template-columns: repeat(9, 1fr);
width: 100%;
grid-template-rows: repeat(8, 1fr);
grid-column-gap: 0px;
grid-row-gap: 0px;
}
.div1 {
grid-area: 2 / 3 / 6 / 6;
max-width: fit-content;
padding-left: 10%;
}
.div2 {
grid-area: 2 / 6 / 4 / 11;
max-width: fit-content;
}
.div3 {
grid-area: 4 / 6 / 6 / 8;
}
without the swiper, things were in their proper places, but as it is it's not working

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

Render components vertically rather than horizontally

I have two divs that are next to each other: artwork__feed and preview
When I map through my db, the images render horizontally and overflow into the preview div.
See here:
Question
How do I render all of my FeedCard components vertically so they don't overflow into my preview div?
Here is my render code:
return (
<div className="feed">
<div className="artwork__feed">
{artworks.map((artwork) => (
<FeedCard
imageUrl={artwork.imageUrl}
title={artwork.title}
artist={artwork.artist}
year={artwork.year}
/>
))}
</div>
<div className="preview">
<div className="phone"></div>
</div>
</div>
);
}
Here is my FeedCard code:
function FeedCard({
imageUrl,
title,
artist,
year,
medium,
height,
width,
category,
}) {
return (
<div className="feed__card">
<div className="feed__card__container">
<div className="feed__category">
<img src={imageUrl} className="artwork__image__feed" />
</div>
<div className="artwork__info">
<div className="artwork__title__artist">
<h1>{title}</h1>
<p>{artist}</p>
</div>
<div className="artwork__bid_button">
<button>Bid</button>
</div>
</div>
</div>
</div>
);
}
And here is my Feed.css code:
.artwork__feed {
display: flex;
align-items: center;
background-color: white;
}
probably grid is your best option:
.artwork__feed {
display: grid;
/*this will give two equal columns*/
grid-template-columns: 1fr 1fr;
align-items: center;
background-color: white;
}

React JS shopping cart add functions

Hi guys and privet from Russia :)
I am trying to build a shopping cart but struggling to add certain functionalities by using React JS only (not redux or node)
This is my code so far:
App.js
import React from "react";
import Navbar from "./components/Navbar";
import Home from "./components/Home";
import "./App.css";
function App() {
return (
<div className="App">
<Navbar />
<Home />
</div>
);
}
export default App;
Home.js*components*
import React, { useState } from "react";
const Home = () => {
const [basketNumbers, setBasketNumbers] = useState(0);
const addToBasket = () => {
setBasketNumbers(setBasketNumbers + 1);
};
return (
<div className="container">
<div className="image">
<img
src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTVWhIi-Mq_A6psrTdfOuElSh7p8y5AzevI7cLWnSLAr0BkQlT0&usqp=CAU"
alt="A green Beautiful dress"
/>
<h3>Green Dress</h3>
<h3>15€</h3>
<a onClick={addToBasket} className="addToCart cart1" href="#">
Add To Cart
</a>
</div>
<div className="image">
<img
src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxAQDxANDw8QDw4QDhAOEA8QDw8PDw8QFhEWFhYRFRUYHSggGBolGxYVITEhJSkrLi4uFyAzODMtNygtLisBCgoKDg0OGxAQGC0lIB8tLSstLS0tLS0tLS0rLS0tLS0tLS0tLSstKy0tLS0rLS0tLS0tLS0tLS0tLS0rLS0tLf/AABEIARMAtwMBEQACEQEDEQH/xAAbAAACAgMBAAAAAAAAAAAAAAAAAQIFAwQGB//EAEMQAAIBAgQCCAMECAQFBQAAAAECAAMRBBIhMQVBBhMiUWFxg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wlOiop0kCIOQ5nvJ3J8TNUzM93l5Mt8lua87llkaxaAQN3LKpFIESkCDJAxOkK1aqwOO/SKbYVD3V1/+upNlJ1t6vhM8uW0/wDr9YafRbChaVMHRrXJ8TrOC0807ZcRe02mV/UAXtE7a7gfXb1hzxb1ee8WxHW1XqC1na4tzUaC/oJ6WHHyUiH0fDY+THHrPVBjptNroQ/4Y9T4EJvztZfc6TG2vNoy5cVPfmPr+TawPRW7Xqt2fuJz825envOeaxt5Gbi4/wDHC1XgNNXVlGVVAGQbEjmTvMotqNNVeNyVpNPXzSxtJlBYKSB3AmYy49RKt4Vwj4qjnPUa57Ouu5J8z/e85IibS6MmStO07XuAwRpZiAczEFiRbYWHlpynRWuocd7c87lcYTFssyapqt8Pj77yaYzDep1LyIzAwETIEYRa5ZVIrKI5IESkKxPTgaddJVUHHsPTeketAZUOcKwBBexVd/FpLTqst+G9q29nz6KvhCW05ATjq67SzU0NWu5vdKaFQOWY/wDab8UdWjLPaEqXAsO6IzUUuUUkgZbm2+lp0VtOu7ZXi81Y1F5Z6fBaK/BRQHvy3PudZeaUtxWW/S15Zv8AhJPKTbVzJDhJHKNpzJJwvvkSbNqnw1RvG2PMzf4VZEQOBU8oEDwteUJtNMABIxbNOlaGLLeYoJQQLi0BWgFoCtCkUl2MNemLHS+mwjY8+x3ERVurdgguSgB+EWsAGF9cy6jc3tpvzWtM93o1w0jrWfxSVQFsAyVCSFuG6t7G2htv3DW8kRPklrxSesxK74Fw3LTYupvUNyGBBt3943M30jUOXJfmttZ0cIiqEUaKABcljYd5OpmbHbItIDlKbGWQPJCkUgLqpQ+rgHVwh5ZEPLCArAAsjEdXARpwLZoETAcBwFARgYWwlInMadMtrqUUk/KELqEW+VFX8KhfpDKGMqJVRIhStCoiA4DtCiEBgAEILQFCCEAkQGALA//Z"
alt="A beautiful Hot Pink Dress"
/>
<h3>Pink Dress</h3>
<h3>350€</h3>
<a onClick={addToBasket} className="addToCart cart2" href="#">
Add To Cart
</a>
</div>
<div className="image">
<img
src="https://m.media-amazon.com/images/I/71dAgPUbwKL._SR500,500_.jpg"
alt="A beautiful Black Dress"
/>
<h3>Black Dress</h3>
<h3>400€</h3>
<a onClick={addToBasket} className="addToCart cart3" href="#">
Add To Cart
</a>
</div>
<div className="image">
<img
src="https://ae01.alicdn.com/kf/He938e0d8636a44c9a4440109bf998d67j/Off-Shoulder-Elegant-Backless-Long-Royal-Blue-Evening-Dresses-2019-Lace-Up-Party-Maxi-Dress-Formal.jpg_640x640q70.jpg"
alt="A Beautiful Blue Dress"
/>
<h3>Blue Dress</h3>
<h3>250€</h3>
<a onClick={addToBasket} className="addToCart cart 4" href="#">
Add To Cart
</a>
</div>
<div className="image">
<img
src="https://ae01.alicdn.com/kf/HTB1Lpp9XAPoK1RjSZKbq6x1IXXaf/Summer-Sexy-Spaghetti-Strap-Ruffle-Women-Dress-Backless-A-Line-Formal-Evening-Party-Dress-Short-Front.jpg_640x640q70.jpg"
alt="A beautiful Red Dress"
/>
<h3>Red Dress</h3>
<h3>150€</h3>
<a onClick={addToBasket} className="addToCart cart5" href="#">
Add To Cart
</a>
</div>
<h1>Current Number In Cart {basketNumbers}</h1>
</div>
);
};
export default Home;
Navbar.js *components*
import React from "react";
function Navbar() {
return (
<header>
<div className="overly" />
<nav>
<h2>Shop</h2>
<ul>
<li>
Home
</li>
<li classname="cart">
{" "}
<a href="#">
<ion-icon name="cart" />
Cart<span> 0 </span>
</a>
</li>
</ul>
</nav>
</header>
);
}
export default Navbar;
This is my CSS just in case:
li a {
padding: 5px;
background-color: white;
text-decoration: none;
}
.cart ion-icon {
vertical-align: bottom;
font-size: 20px;
padding-right: 5px;
}
.cart a {
background-color: royalblue;
color: white;
cursor: pointer;
text-decoration: none;
}
.container {
display: flex;
justify-content: center;
flex-wrap: wrap;
margin-top: 50px;
padding-bottom: 100px;
}
.img {
margin-right: 20px;
margin-left: 20px;
position: relative;
overflow: hidden;
}
.addToCart {
position: absolute;
width: 100%;
background-color: darkgray;
transition: all 0.3s ease-in-out;
opacity: 0;
cursor: pointer;
text-align: center;
}
.image:hover .cart1,
.image:hover .cart2,
.image:hover .cart3,
.image:hover .cart4,
.image:hover .cart5 {
bottom: 50px;
opacity: 1;
padding: 10px;
text-decoration: none;
}
What I would like to add to this code:
Add to cart click will add the product to the cart and not just show it on the bottom part of the page
Add a total which changes whenever a new item is added to the cart
Add a free shipping for a car above 500 EUR, else having a message saying you're not entitled to a free shipping.
Thank you so much :)
well i can't actually do all what you want bcs... you shouldn't actually ask people here to add those features for you bcs i think they take so much lines, you should try to add them yourself and then if your code doesnt work, you just ask here, anyways i found a mistake in your code and i'm gonna correct it for ya:
Home.jscomponents
import React, { useState } from "react";
const Home = () => {
const [basketNumbers, setBasketNumbers] = useState(0);
const addToBasket = () => {
setBasketNumbers(oldBasketNum => oldBasketNum + 1); //this is the correct way to update the state on click, bcs u wrote setBasketNumbers +1 which won't work
};
return (//the rest of your code here)
Hope this was helpfull, thanks
**
Edit:
**
You also should add more components to save you some space in your render method like this:
Item component:
import React from "react";
const Item = (props) => {
return (
<div className="image">
<img src={props.img} alt={props.alt} />
<h3>props.name</h3>
<h3>props.price</h3>
<a onClick={props.addToBasket} className="addToCart cart1" href="#">
Add To Cart
</a>
</div>
);
};
export default Item;
Home.js component:
import React, { useState } from "react";
import Item from "./item.js";
const Home = () => {
const [basketNumbers, setBasketNumbers] = useState(0);
const addToBasket = () => {
setBasketNumbers((oldBasketNum) => oldBasketNum + 1); //this is the correct way to update the state on click, bcs u wrote setBasketNumbers +1 which won't work
};
return (
<div className="container">
<Item name="" price="" img="" alt="" /> //you fill this props as you want
the items to be
<Item name="" price="" img="" alt="" /> //you could also make this more
dynamic using arrays
</div>
);
};

Resources