【发布时间】:2022-01-04 02:44:35
【问题描述】:
在简单的 HTML 结构中,我可以实现如下。我想知道如何对 React 和 Styled Component 做同样的事情。
HTML
<div className="slider">
<section>Content A</section>
<section>Content B</section>
</div>
我可以像这样定位部分的样式。
.slider section {
//some styling
};
如何在 React with Styled Component 中实现同样的效果?在这种情况下,我的滑块 div 是一个样式组件,该部分是一个 React 组件,如下所示。
<Slider>
<SectionComponent text="Content A" />
<SectionComponent text=" Content B" />
</Slider>
这是我尝试过的,在 Slider CSS 代码块中我尝试设置 SectionComponent 的样式但不起作用。
样式化组件 CSS
export const Slider = styled.div`
//some css styling
Slider SectionComponent {
//styling of the SectionComponent
}
`;
【问题讨论】:
标签: javascript html css reactjs styled-components