css - 为什么我的 CSS 样式不适用于页面?

标签 css reactjs create-react-app

如何使用来自不同文件的 CSS 来设计 React 应用程序的样式?这段代码有什么问题?

Button.css

.Button {
  cursor: pointer;
  margin-left: 5px;
  margin-bottom: 15px;
  background-color: aquamarine;
}

Button.js

import React from 'react';
import classes from './Button.css';

const button = (props) => (
<div>
    <button className={classes.Button}>Click ca să dai muie</button>
</div>
);

export default button;

<Button />之后在有状态组件中调用组件。

PS:我使用的是 create-react-app v2 和 React 16.8.6

最佳答案

仅将 CSS 导入您的组件。并将样式用作 Strings

import React from 'react';
import './Button.css';

const button = (props) => (
<div>
    <button className="Button">Click ca să dai muie</button>
</div>
);

export default button;

关于css - 为什么我的 CSS 样式不适用于页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55958400/

相关文章:

javascript - 是否可以在 React Native 中从其无状态组件子级更改父级的状态?

javascript - 使用 View 作为按钮 - React Native

javascript - create-react-app 子文件夹项目不 lint

reactjs - 构建后index.html中的相对路径

css - 一个背景图像不显示而另一个是

javascript - 如何查找 innerHtml(text) 超出容器元素宽度

reactjs - react Apollo 查询太快了

node.js - 在 Node v13 中使用 @babel/register 来创建 React 应用程序

css - Firefox 如何在单元格表格内显示滚动条?

html - 将 iframe 保持在图片中间