【发布时间】:2021-05-12 23:38:24
【问题描述】:
我有两个反应组件。
- 列表容器
- 列表
列表需要在列表容器内。像这样:
<Container innerhtml={<List></List>} ></Container>
两个组件的内容都会呈现。然而,孩子的造型被父母的造型所覆盖。 (本例中为背景色)
这是完整的代码:
import React from "react";
export default function main() {
return <div>
<Container
innerhtml={<List></List>}
></Container>
</div>
}
function List() {
return <div style={{ backgroundColor: "#red!important", height: "150px", width: "150px" }}>
this is a list
</div>
}
function Container(props) {
return <div style={{ backgroundColor: "#94e49d38", height: "400px", width: "100vw-10px" }}>
this is container
{props.innerhtml}
</div>
}
我觉得可能和这个类似:Style not working for innerHTML in Angular
但是我找不到 React 等价物。
如何让列表样式起作用?
谢谢
【问题讨论】:
标签: javascript html css reactjs