【发布时间】:2021-11-23 14:57:48
【问题描述】:
好的,所以我正在尝试使用 React javascript 库制作一个 todolist。
问题
我正在尝试将网站屏幕除以 2 个 div。其中,一个在顶部 50%,另一个在底部 50%。然而,
.top{
width: 50%;
float: top;
}
.bottom{
width: 50%;
float: bottom;
}
好像不行..
我试过了
添加html, body { height: 100%; }
添加.App {text-align: center;margin:0;height:100%;}
它没有任何改变。
示例
import React from 'react'
import './App.css';
import Navigation from './components/ToDoNav';
function App() {
return (
<div className="App">
<Navigation/>
<div className="top">
<h1>Copy</h1>
</div>
<div className="bottom">
<h1>Design</h1>
</div>
</div>
);
}
export default App;
App.js
.App {
text-align: center;
margin:0;
height:100%;
}
html, body {
height: 100%;
}
.top{
height: 50%;
float: top;
}
.bottom{
height: 50%;
float: bottom;
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
App.css
结果
【问题讨论】:
-
试试这个
body { margin: 0 auto; }