我目前正在使用nextjs作為框架構建react組件。我在vanilla react build上也遇到了這個問題,但是在每一頁上,頁腳都呈現得很好,在index.js頁面之外,它呈現所有頁面特定的內容,就在navbar的底部。
以下是_app.js文件:
import Navbar from './Nav';
import Footer from './Footer';
import "bootstrap/dist/css/bootstrap.min.css";
import "semantic-ui-css/semantic.min.css";
import Script from 'next/script';
import { useEffect, useRef } from "react";
export default function App({ Component, pageProps }) {
useEffect(() => {
require("bootstrap/dist/js/bootstrap.bundle.min.js");
}, []);
return (
<>
<Script src="https://static.elfsight.com/platform/platform.js" data-use-service-core defer />
<Navbar />
<Component {...pageProps} />
<Footer/>
</>
)
}
以下是index.js文件:
import React from 'react';
import Link from 'next/link';
//import styles from "../styles/globals.css"
import Footer from './Footer'
import SecondLanding from './SecondLanding'
import FirstLanding from './FirstLanding'
import ThirdLanding from './ThirdLanding'
import FourthLanding from './FourthLanding'
import Head from 'next/head'
export default class extends React.Component {
render() {
return (
<>
<Head>
<title>Title_here</title>
</Head>
<div className='main_container background_photo font-face-gm'>
<div className="body">
<div className="wrapper">
<FirstLanding />
<SecondLanding />
<ThirdLanding />
<FourthLanding />
</div>
</div>
</div>
</>
)
}
}
以下是預期的行為:以下是意外的行為:
我知道這是一個我在其他論壇上看到的常見問題,但我無法通過這些線程修復這個問題,經過幾個小時的修補后我回來了。
我不認為這是必要的,這里是頁腳代碼:
import Link from 'next/link';
import styles from '../styles/Footer.module.scss';
import { router } from "next/router";
import Contact from '../../public/images/contact.png'
import Image from 'next/image';
const Footer = () => {
return (
<>
<footer className={styles.footer}>
<div className={styles.container}>
<div className={styles.firstContainer}>
<div className={styles.contactContainer}>
<Image className={styles.contactImg} src={Contact} width={32} height={32} alt='cash' />
<h3 className={styles.contactHeader}><strong>Contact Us!</strong></h3>
<p className={styles.contactInfo}>
(651)472-2736<br/>
sales@spiesscarpet.com</p>
</div>
</div>
<div className={styles.infoContainer}>
<div className={styles.waves}>
<div className={styles.wave} id={styles.wave1}></div>
<div className={styles.wave} id={styles.wave2}></div>
<div className={styles.wave} id={styles.wave3}></div>
<div className={styles.wave} id={styles.wave4}></div>
</div>
<div className={styles.topContainer}>
<ul className={styles.menu}>
<li className={styles.menu__item}>
<Link className={styles.menu__link} href="/about"><p className={styles.link}><strong>About</strong></p></Link>
</li>
<li className={styles.menu__item}>
<Link className={styles.menu__link} href="/services"><p className={styles.link}><strong>Services</strong></p></Link>
</li>
<li className={styles.menu__item}>
<Link className={styles.menu__link} href="/contact"><p className={styles.link}><strong>Contact</strong></p></Link>
</li>
<li className={styles.menu__item}>
<Link className={styles.menu__link} href="/testimonials"><p className={styles.link}><strong>Testimonials</strong></p></Link>
</li>
<li className={styles.menu__item}>
<Link className={styles.menu__link} href="/faq"><p className={styles.link}><strong>FAQ</strong></p></Link>
</li>
</ul>
</div>
<div className={styles.bottomContainer}>
<p style={{ opacity: 0.75 }}>©2023 Nick Spiess | All Rights Reserved</p>
</div>
</div>
<div className={styles.buttonContainer}>
<Link style={{ textDecoration: 'none' }} href='/quote' passHref>
<button
className={`${styles.btnMd} ${styles.navButton}`}
onClick={() => router.push('/quote')}
>
<strong>Get a Free Quote!</strong>
</button>
</Link>
</div>
</div>
</footer>
<footer className={styles.mobileFooter}>
<div className={styles.container}>
<div className={styles.infoContainer}>
<div className={styles.waves}>
<div className={styles.wave} id={styles.wave1}></div>
<div className={styles.wave} id={styles.wave2}></div>
<div className={styles.wave} id={styles.wave3}></div>
<div className={styles.wave} id={styles.wave4}></div>
</div>
<div className={styles.topContainer}>
<ul className={styles.menu}>
<li className={styles.menu__item}>
<Link className={styles.menu__link} href="/about"><p className={styles.link}><strong>About</strong></p></Link>
</li>
<li className={styles.menu__item}>
<Link className={styles.menu__link} href="/services"><p className={styles.link}><strong>Services</strong></p></Link>
</li>
<li className={styles.menu__item}>
<Link className={styles.menu__link} href="/contact"><p className={styles.link}><strong>Contact</strong></p></Link>
</li>
<li className={styles.menu__item}>
<Link className={styles.menu__link} href="/testimonials"><p className={styles.link}><strong>Testimonials</strong></p></Link>
</li>
<li className={styles.menu__item}>
<Link className={styles.menu__link} href="/faq"><p className={styles.link}><strong>FAQ</strong></p></Link>
</li>
</ul>
</div>
</div>
<div className={styles.buttonContainer}>
<Link style={{ textDecoration: 'none' }} href='/quote' passHref>
<button
className={`${styles.btnMd} ${styles.navButton}`}
onClick={() => router.push('/quote')}
>
<strong>Get a Free Quote!</strong>
</button>
</Link>
</div>
<div className={styles.bottomContainer}>
<p style={{ color: 'white', }}>©2023 Nick Spiess | All Rights Reserved</p>
</div>
</div>
</footer>
</>
);
};
export default Footer;
css:
.bottomContainer {
margin-top: 5px;
text-align: center;
display:flex;
justify-content: center;
align-items: center;
}
.mobileFooter {
display: none;
}
.contactHeader {
font-size: 1.3em;
color: white;
}
.infoContainer {
margin-left: 50px;
margin-right: 50px;
align-items: center;
justify-content: center;
text-align: center;
flex-grow: 1;
display: inline; /* Add display flex */
justify-content: center; /* Center horizontally */
}
.buttonContainer {
display: flex;
justify-content: center;
align-items: center;
}
.contactImg {
margin-bottom: -10px;
}
.contactContainer {
display: inline-block;
margin-bottom: 30px;
}
.contactInfo {
text-align: center;
display:flex;
align-items: center;
width: 90%;
}
.firstContainer {
display: inline;
text-align: center;
}
.topContainer {
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 15px;
}
.container {
width: 90%;
margin-bottom: -5vh;
display: flex;
align-items: center;
}
.footer {
position: relative;
background: #3586ff;
min-height: 250px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
margin-top:0vh;
}
.social-icon,
.menu {
display: flex;
justify-content: center;
align-items: center;
margin-top: 10px;
flex-wrap: wrap;
}
.social-icon__item,
.menu__item {
list-style: none;
}
.firstContainer {
}
.buttonContainer {
display: flex;
justify-content: center;
align-items: center;
}
.navButton {
padding: 10px 20px;
background-color: #fff;
color: black;
border: solid rgb(102, 176, 255) 3px;
border-radius: 20px;
font-size: 1.35rem;
font-family: Montserrat;
font-weight: 400;
transition: background-color 0.3s ease, color 0.3s ease;
cursor: pointer;
}
.navButton:hover {
background-color: #3586ff;
color: #fff;
border: solid white 3px;
}
.social-icon__link {
font-size: 2rem;
color: #fff;
margin: 0 10px;
display: inline-block;
transition: 0.5s;
text-align: center;
}
.link {
text-align: center;
}
.link:hover {
transform: translateY(-2px);
}
.social-icon__link:hover {
transform: translateY(-10px);
}
.menu__link {
font-size: 1.3rem;
color: rgba(255, 255, 255, 0.981);
margin: 0 10px;
display: inline-block;
transition: 0.5s;
text-decoration: none;
font-weight: 800;
}
.menu__link:hover{
color: white;
}
.menu__link:hover {
opacity: 1;
}
.footer p {
color: #fff;
margin: 15px 0 0px 0;
font-weight: 400;
font-size: 1.25rem;
font-family: Montserrat;
}
.wave {
position: absolute;
top: -100px;
left: 0;
width: 100%;
height: 100px;
background: url("https://i.ibb.co/wQZVxxk/wave.png");
background-size: 1000px 100px;
}
.wave#wave1 {
z-index: 1000;
opacity: 1;
bottom: 0;
animation: animateWaves 8s linear infinite;
}
.wave#wave2 {
z-index: 999;
opacity: 0.5;
bottom: 10px;
animation: animate 8s linear infinite !important;
}
.wave#wave3 {
z-index: 1000;
opacity: 0.2;
bottom: 15px;
animation: animateWaves 5s linear infinite;
}
.wave#wave4 {
z-index: 999;
opacity: 0.7;
bottom: 20px;
animation: animate 5s linear infinite;
}
@keyframes animateWaves {
0% {
background-position-x: 1000px;
}
100% {
background-positon-x: 0px;
}
}
@keyframes animate {
0% {
background-position-x: -1000px;
}
100% {
background-positon-x: 0px;
}
}
@media (max-width: 768px) {
.footer {
}
.firstContainer {
width: 25%;
}
.contactInfo {
text-align: center;
}
.infoContainer {
margin-left: 50px;
margin-right: 50px;
}
}
/* Media query for smaller devices */
@media (max-width: 700px) {
.footer {
display: none;
}
.mobileFooter {
text-align: center;
}
.mobileFooter .container {
width: 90%;
padding-bottom: 15px;
display: flex;
align-items: center;
}
.container {
width: 90%;
display: flex;
align-items: center;
flex-direction: column;
margin-bottom: 0vh;
margin-top: 15px;
}
.buttonContainer {
margin-top: 0px;
margin-bottom: 15px;
}
.menu {
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
padding: 0;
}
.menu__item {
flex: 0 0 100%;
margin-bottom: 10px;
}
.menu__link {
text-align: center;
font-size: 1.2rem;
}
.topContainer {
display: inline;
}
.firstContainer {
display: none;
}
.mobileFooter {
width: 100%;
position: relative;
background: #3586ff;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
text-align: center;
margin-bottom: 0; /* Add this line */
}
.firstContainer,
.infoContainer {
width: 100%;
margin: 0;
}
.navButton {
width: 100%;
font-size: 1.1rem; /* Adjust the font-size value as needed */
padding: 8px 16px; /* Adjust the padding values as needed */
margin-top: 2px;
margin-bottom: 7px;
}
}
謝了。