2016-06-28 34 views
1

我想将我的直接子节点<div id='root'>设置为height: 100%,但是我意识到反应是添加了一个额外的反应节点层,以防止孩子的height: 100%无法正常工作。下面的示例:ReactJS组件高度'100%'

<html> 
<body> 
<div id="root"> <== root node is height:100%, still good here 
    <div data-reactid=".0"> <== added by react? broke the child height 
    <div data-reactid=".0.$/=10" style="height: 100%; background-color: gray;"> <== child can't get 100% height of #root because of the empty div wrapping it 

我的JSX代码不加入这个data-reactid='.0'包装DIV,所以我没有在样式控制。所以这里的问题是,我如何控制这个包装div,或者如何使用其他方法实现height:100%

谢谢!

+1

React确实没有添加包装div,任何小提琴? –

回答

1

包装DIV应该是在你的代码,这样的事情:

render() { 
     return (
      <div> // the wrapper div 
       <div style={{height: '100%','background-color': 'gray'}}></div> 
      </div>); 
    } 
0
body{ 
height:100% 
} 

#root div{ 
height:100% 
} 

在你的CSS添加此,它为我工作。

0
#root > div { 
    height:100%; 
}