【问题标题】:Ant Design Notification not using custom styling in React AppAnt Design Notification 未在 React App 中使用自定义样式
【发布时间】:2020-03-26 21:05:17
【问题描述】:

我目前在尝试为 Ant Design 的通知模块使用自定义样式时遇到问题。这是我的代码

import React from "react";
import ReactDOM from "react-dom";
import "antd/dist/antd.css";
import "./index.css";
import "./notification.less";
import { Button, notification } from "antd";

const openNotification = () => {
  notification.open({
    message: "Notification Title",
    description:
      "This is the content of the notification. This is the content of the notification. This is the 
content of the notification.",
    className: "notification-type-info"
  });
};

ReactDOM.render(
  <Button type="primary" onClick={openNotification}>
    Open the notification box
  </Button>,
  document.getElementById("container")
);

这是我的 notification.less 文件中的内容

.notification-type-info {
  width: 200px;
  background-color: #1890ff;
}

这是我测试代码的地方 https://codesandbox.io/s/customized-style-ant-design-demo-n0yh7

我做错了什么?

【问题讨论】:

    标签: reactjs antd


    【解决方案1】:

    答案是使用 ::global 修改父 ant 容器,并且只在所需组件中调用 css 类。

    【讨论】:

      猜你喜欢
      • 2019-03-09
      • 2023-01-27
      • 2019-10-22
      • 2021-10-27
      • 2020-08-21
      • 2020-02-22
      • 2019-12-09
      • 2019-01-16
      • 2021-06-05
      相关资源
      最近更新 更多