Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将常规嵌套css更改为样式化组件?_Css_Reactjs_Styled Components - Fatal编程技术网

如何将常规嵌套css更改为样式化组件?

如何将常规嵌套css更改为样式化组件?,css,reactjs,styled-components,Css,Reactjs,Styled Components,我有这个CSS样式,我想在react中更改为样式化组件: .movie-page .movie-details { display: flex; flex-direction: column; max-width: 800px; margin: 20px auto 60px auto; } .movie-page .movie-details h1 { line-height: 1.5em; } .movie-page .movie-details h1 span {

我有这个CSS样式,我想在react中更改为样式化组件

.movie-page .movie-details {
  display: flex;
  flex-direction: column;
  max-width: 800px;
  margin: 20px auto 60px auto;
}

.movie-page .movie-details h1 {
  line-height: 1.5em;
}

.movie-page .movie-details h1 span {
  font-size: inherit;
  font-weight: normal;
  padding-left: 1rem;
  color: #bbb;
  line-height: inherit;
}
我有点困惑标签嵌套是如何工作的。我正在使用样式化组件进行此操作:

const MovieDetails = styled.div`
  display: flex;
  flex-direction: column;
  max-width: 800px;
  margin: 20px auto 60px auto;

  h1 {
    line-height: 1.5em;
  }

  h1 span {
    font-size: inherit;
    font-weight: normal;
    padding-left: 1rem;
    color: #bbb;
    line-height: inherit;
  }
`;

这个代码看起来正常吗?我的h1标签看起来像p标签

你应该可以这样选择。Bt您还可以执行以下操作,看起来更整洁:

const MovieDetailsHeader = styled.h1 `
   line-height: 1.5em;
   span {
        font-size: inherit;
        font-weight: normal;
        padding-left: 1rem;
        color: #bbb;
        line-height: inherit;
    }
`

谢谢你的提示。如果我没有将h1标记指定为
font-size:2em
,您知道为什么它会显示为p标记吗?请显示相应的代码。此外,如果你认为任何答案有帮助,别忘了投赞成票