gpt4 book ai didi

reactjs - 添加 CSS 来响应创建的元素,例如 data-reactroot

转载 作者:行者123 更新时间:2023-12-03 13:06:48 28 4
gpt4 key购买 nike

在我的根div下,react“自动”创建另一个div。有没有办法向该 div 添加一个类?我需要添加 height: 100% 来防止背景内容在显示覆盖层时在移动设备中滚动。

这就是我检查网站上的元素时显示的方式。单击按钮时,我需要将 height:100% 添加到 data-reactroot div。但那个 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%';
}

但是有没有更好的方法呢?这感觉有点像黑客(以一种糟糕的方式)

最佳答案

CSS 中的

#root > [data-reactroot] { height: 100% } 应该可以工作。

或者只是标签本身:

[data-reactroot] { ... }

关于reactjs - 添加 CSS 来响应创建的元素,例如 data-reactroot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41259244/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com