我目前正在嘗試設計一個 React 項目的樣式,其中 App.js 主要提供路由和導航到其組件的功能:
應用程序.js
import {useState, useEffect} from 'react';
import Models from './pages/Models';
import Loadingpage from './pages/Loadingpage';
import Output from './pages/Output';
import './App.css';
import {BrowserRouter, Route, Switch} from "react-router-dom";
function App() {
// state variables and function declarations.....
return (
<Browserouter>
<Switch>
<Route path="/" exact>
{isLoading===true?
<Loadingpage/>
:
<Models/>
</Route>
<Route path="/models/output" exact>
<Output/>
</Route>
</Switch>
</Browserouter>
);
}
流程如下:
<div className="Loading page"
style={{
display: 'flex',
alignItems: 'center',
background: "#A0C5E8",
justifyContent: 'center',
}}
>
<FlowerSpinner size={props.size} color={props.color}/>
</div>
這些組件完全正常工作,它們的工作方式與加載頁面相同。它們只是作為一個組件渲染(或者看起來如此)。但是,組件頁面只呈現它們佔用的空間部分,這使得底層背景看起來需要在某處更改。這是發生的事情:
如圖所示,頁面有自己的 div,其中顯示了各自的背景。我已經嘗試將每個組件包裝在具有相應背景顏色的 div 中,並將整個 app.js 包裝在一個 div 中:例如。
<div
style={{
display: 'flex',
alignItems: 'center',
background: "#A0C5E8",
justifyContent: 'center',
}}
>
<Loadingpage size={300} color="black"/>
</div>
如何成功更改基本背景顏色?幫助將不勝感激,感謝閱讀!
要更改整個頁面的背景顏色,您需要將樣式應用到 html 的 body 標籤並在 index.js 或 App.js 文件中導入樣式:
樣式.css
body {
background : #A0C5E8
}
index.js 或 App.js
import './styles.css'
Dieser Artikel stammt aus dem Internet. Bitte geben Sie beim Nachdruck die Quelle an.
Bei Verstößen wenden Sie sich bitte [email protected] Löschen.
Lass mich ein paar Worte sagen