简体   繁体   English

如何在 Antd 的 Modal 中更改样式?

[英]How to change styles in Modal of Antd?

In a React project, I'am using Ant Design (Antd) as CSS framework.在一个 React 项目中,我使用 Ant Design (Antd) 作为 CSS 框架。 So we have a requirement to change the styling of Modal which is the component of Antd.所以我们需要改变作为 Antd 组件的 Modal 的样式。 To change its border radius of Modal component is expected, but, with many attempts, all in vain.改变它的 Modal 组件的边界半径是预料之中的,但是,经过多次尝试,一切都是徒劳的。 Is there any appropriate solution?有没有合适的解决方案?

  1. Modal Component模态组件
<Modal
        title="Basic Modal"
        visible={isModalVisible}
        onOk={handleOk}
        onCancel={handleCancel}
        className="modalStyle"
        //bodyStyle={{ borderRadius: "20px" }} {/* Also tried with bodyStyle property */}
      >
        <p>Some contents...</p>
        <p>Some contents...</p>
        <p>Some contents...</p>
</Modal>

index.css索引.css

.modalStyle {
  border-radius: 20px;
}

.newStyle {
  border-radius: 20px;
}

/* applied style to its root properties, but no change */
.ant-modal-content {
  border-radius: 20px;
}

Following is the codesandbox link: https://codesandbox.io/s/basic-antd4168-forked-rz764以下是代码框链接: https ://codesandbox.io/s/basic-antd4168-forked-rz764

Add:添加:

.modalStyle2 .ant-modal-header {
  border-radius: 20px 20px 0 0;
}

or或者

.modalStyle .ant-modal-header {
  border-radius: 20px 20px 0 0;
}

Check codesandbox https://codesandbox.io/s/basic-antd4168-forked-0nddw检查代码框https://codesandbox.io/s/basic-antd4168-forked-0nddw

className prop on Modal component applies to the root element however for styling border radius you should you apply it to nested .ant-modal-content and .ant-modal-header elements: Modal 组件上的 className 属性适用于根元素,但是对于样式边框半径,您应该将其应用于嵌套.ant-modal-content.ant-modal-header元素:

模态组件上的类名

The modal will not come under the direct CSS.模态将不属于直接 CSS。 You have to write the things in a global CSS file then it will work .你必须在一个全局 CSS 文件中编写这些东西,然后它才能工作 Write below in global CSS, it will work用全局CSS写在下面,它会起作用

.modalStyle .ant-modal-content{
   background-color: #01579b;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM