我正在尝试在我的React应用程序中使用Flexbox来创建占据完整宽度和高度的简单双列网页。CSS 100%高度在React应用程序中不起作用
我可以通过它自己使用HTML和CSS,但不能在React应用程序中使用。
到目前为止,我有:
:root {
overflow-x: hidden;
height: 100%;
}
body {
min-height: 100%
}
.flexbox {
height: 100%;
display: flex;
}
.left {
flex: 0 0 200px;
height: 100%
}
.right {
flex: 1
}
和:
<div class="flexbox">
<div class="left">
Left
</div>
<div class="right">
Right
</div>
</div>
我意识到我需要在我index.html
占额外<div id="root"></div>
标签,所以我还增加了以下内容我的CSS :
#root {
height: 100%;
}
而我的render
功能:
render() {
return (
<div className="flexbox">
<div className="left">Left</div>
<div className="right">Right</div>
</div>
)
}
但这不起作用。列存在但不是全高。为什么不?
原谅我,如果我听起来很蠢,但你导入CSS文件吧? – Dane
是的,我是.'left'和'right'实际上有背景颜色,他们显示。 – tommyd456
你可以参考这个链接: - https:// stackoverflow。com/questions/6654958/make-body-have-100-of-the-browser-height –