【发布时间】:2022-01-04 00:46:26
【问题描述】:
由于某种原因,设置 className 没有设置我的属性:
export default class MyComponent extends Component {
render() {
return(
<div className={styles.example}>
</div>
)
}
}
const styles = StyleSheet.create({
example: {
background: 'black',
width: '100px',
height: '100px'
}
})
它只是呈现类似的东西
<div class="175">
</div>
没有样式信息(“类”175 没有 CSS 规则)
为什么不(如我所料)以 styles__example___2w27N 之类的名称结束,并在浏览器中指定 CSS 规则
.styles__example___2w27N {
background-color: 'black';
height: 100px;
width: 100px;
}
如何应用我的 CSS?
如果我使用style={styles.example}(而不是className),我实际上会得到this error:
style属性需要从样式属性到值的映射,而不是字符串。
我更喜欢使用className,因为
- 我已经指定了悬停和活动样式,
style可以使用这些样式吗? - 我想手动添加和覆盖一些内联样式
【问题讨论】:
-
@Vektor 我应该看什么?
-
@theonlygusti,你用的是 react-native 还是 react js web?
-
react-native和reactJS基本相似,但它们不能共享相同的代码
标签: javascript reactjs react-native