在我的根div下,react将“自动”创建另一个div。有没有一种方法可以向该div中添加类?我需要增加高度:100%以防止显示叠加层时背景内容在移动设备中滚动。
这是当我检查站点上的元素时如何显示的。单击按钮时,我需要向data-reactroot div添加height:100%。但是那个div在我的源代码中不存在。
<div id="root"> <div data-reactroot data-reactid="1" data-react-checksum="161698...
我可以在容器的componentDidMount()中添加此代码
let root = document.querySelectorAll('[data-reactroot]')[0]; if (root) { root.style.height = '100%'; }
但是没有更好的方法吗?这感觉像是一种hacky(以一种不好的方式)
#root > [data-reactroot] { height: 100% } 在您的CSS中应该可以工作。
#root > [data-reactroot] { height: 100% }
或者只是标签本身:
[data-reactroot] { ... }