【发布时间】:2019-06-22 22:25:32
【问题描述】:
我是 React 新手,我对与 rwmc 组件相关的 CSS 样式有些困惑。
我只是通过从 '@rmwc/button' 包中导入它来在网页上呈现两个 Button 组件。我正在关注本教程
https://jamesmfriedman.github.io/rmwc/buttons
我还为此组件导入了材料设计,例如
导入'@material/button/dist/mdc.button.css';
现在我的屏幕上有两个按钮,对于其中一个按钮组件,我提到了 className 属性。在那个类中,按钮颜色刚刚变红,工作正常,但我在这里想知道,除了改变按钮的颜色之外,在 mdc.button.css 中定义的所有其他 css 也只是被应用到这个,我不知道为什么是这样吗,这是正确的行为吗?
我问这个是因为我在这里读到了
https://jamesmfriedman.github.io/rmwc/styling-theming
所有组件上都有material-components-web classNames,您可以添加自己的,这意味着您正在更改主类。
任何帮助将不胜感激。
代码:
import React from 'react';
import ReactDOM from 'react-dom';
import { DrawerHeader } from '@rmwc/drawer';
import { Button, ButtonIcon } from '@rmwc/button';
import '@material/button/dist/mdc.button.css';
//import styles from './index.module.css';
import './index.css'
const MyComponent = props => (
<div>
<Button>Default</Button>
<Button className="myDrawerHeader">Default2</Button>
</div>
);
ReactDOM.render(<MyComponent />, document.getElementById('root'));
index.css
.myDrawerHeader {
color: red !important;
}
屏幕上的输出是这样的,我认为这是错误的。为什么 .mdc 中的所有其他样式都应用于第二个按钮,我刚刚更改了它的颜色。
【问题讨论】:
标签: reactjs