Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.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,如您所见,注销按钮(has classgBuhXv)具有display:flex,而不是内联块,因为父级(ThemedApp,.jCe…)的优先级更高 导致这种情况的规则是p.column{text align:right;}可以被body p.column{text align:left;}覆盖,因为它更具体 它的行为是正确的,但不是我所期望的,如何使注销按钮的优先级更大?问题在于 const globalStyles = styled.div` p { color: ${props =&

如您所见,
注销按钮(has class
gBuhXv
)具有
display:flex
,而不是
内联块
,因为父级(
ThemedApp
.jCe…
)的优先级更高

导致这种情况的规则是
p.column{text align:right;}
可以被
body p.column{text align:left;}
覆盖,因为它更具体

它的行为是正确的,但不是我所期望的,如何使注销按钮的优先级更大?

问题在于

const globalStyles = styled.div`
p {
  color: ${props => props.theme.somecolor};
}
a {
  color: ${props => props.theme.somecolor};
}`
不是样式化组件的正确用法

相反,我必须定义组件并扩展它们:

const P = styled.p`
  color: ${props => props.theme.somecolor};
`
const A = styled.A`
  color: ${props => props.theme.somecolor};
`
const CustomA = A.extend`
  color: mycolor;
`

如果你可以发布两个问题,那么这表明这些问题彼此重复。否则,你应该针对实际被问到的问题量身定制你的答案。是的,他们都是模棱两可的
const P = styled.p`
  color: ${props => props.theme.somecolor};
`
const A = styled.A`
  color: ${props => props.theme.somecolor};
`
const CustomA = A.extend`
  color: mycolor;
`