css - 如何在 React 中覆盖物化 css

标签 css reactjs materialize

我正在使用 React 构建简单的应用程序,并使用 Materilize css。在我的 UserProfile 组件类中导入 UserProfile.css import "./UserProfile.css

/* UserProfile.css */ 

.custom-class {
  margin-top: 30 !important;
  color: pink;
}

render 方法中的 UserProfile 有

<h1 className="custom-class">Title</h1> // Margin is not applyed, but color is pink

我有一个选择

<h1 style={{ marginTop: 30, color: "pink" }}>Title</h1> 

这很好用,但我更喜欢 css 文件中的样式代码。

我不确定这个问题是否与覆盖无关。

最佳答案

你应该在 css 文件中使用 px,将你的代码更改为 margin-top: 30px !important; 它应该可以工作。

如果你想检查 css 中的重写问题,你可以检查你的代码(右键单击你的浏览器并选择检查)并检查它是否交叉。

关于css - 如何在 React 中覆盖物化 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57292289/

相关文章:

javascript - jQuery:将数字包装在一个范围内的div中

css - 样式化父元素 CSS

html - 为什么我的 gif 在 firefox 中像素化而不是在 google chrome 浏览器中像素化?

javascript - 启用当前页面链接的materializecss分页

html - 3 div的中间div占用剩余宽度

reactjs - 在另一个 axios 请求中使用 axios 响应数据

javascript - React JSX 动态 SVG 转换错误

javascript - 将导入移至单独的文件

html - CSS:使用 Materialize 框架在 Chrome 中截断 header

html - 如何在实体化的文本内容后面设置背景幻灯片?