tec*_*ake 3 javascript css flexbox reactjs
我正在尝试使用 React 和 flexbox。通常我可以在 react native 中使用 flexbox 但在 react.js 中无法实现
这是我的 CSS 文件
.wrapper, html, body {
height:100%;
margin:0;
position:absolute;
}
.wrapper {
display: flex;
flex-direction: column;
}
.nav {
background-color: red;
flex:1
}
.main {
background-color: blue;
flex:1
}
Run Code Online (Sandbox Code Playgroud)
这是我的js文件
import React, { Component } from 'react';
import './background.css';
import { Icon } from 'semantic-ui-react'
import Navbar from './navbar'
class Back extends Component {
render() {
return (
<div className="wrapper">
<div className="nav"></div>
<div className="main"></div>
</div>
);
}
}
export default Back;
Run Code Online (Sandbox Code Playgroud)
我只有一个白屏,这可能是什么问题?
谢谢
由于wrapper被定位为绝对的,并且没有内容可以增长,它的宽度折叠为 0。
所以只需position: absolute从.wrapper, html, body规则中删除。
如果您仍想使用position: absolute,则还需要为包装器指定宽度。
.wrapper,
html,
body {
height: 100%;
margin: 0;
}
.wrapper {
display: flex;
flex-direction: column;
}
.nav {
background-color: red;
flex: 1
}
.main {
background-color: blue;
flex: 1
}Run Code Online (Sandbox Code Playgroud)
<div class="wrapper">
<div class="nav"></div>
<div class="main"></div>
</div>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11053 次 |
| 最近记录: |