制作没有任何填充或边距的 antd 模态全屏

making antd modal full screen without any padding or margins

我是编程新手。这里我有一个 antd 模态,我一直在努力寻找一种方法让它全屏显示。我希望模式在打开时是完整的屏幕,并且它不应该有任何边距或填充。例如,在代码中我添加了 width={1000} 但是模态框的左右两边仍然有一些边距。

那么如何使模式在没有任何边距和填充的情况下占据整个屏幕?

代码: https://codesandbox.io/s/otjy6?file=/index.js:539-560

  1. 您需要取消设置 max-widthmargin 模态
.ant-modal {
  max-width: unset;
  margin: unset;
}
  1. 您需要在 ant-modal-centered class
  2. before 伪元素中取消设置 content
.ant-modal-centered::before {
  content: unset;
}

工作Demo

  1. 从您的代码文件中删除模态 widthcentered 属性的固定值:

index.js

import React, { useState } from 'react';
import ReactDOM from 'react-dom';
import 'antd/dist/antd.css';
import './index.css';
import { Modal, Button } from 'antd';

const App = () => {
  const [visible, setVisible] = useState(false);
  return (
    <>
      <Button type="primary" onClick={() => setVisible(true)}>
        Open Modal of 1000px width
      </Button>
      <Modal
        title="Modal 1000px width"
        // This was removed
        // centered
        visible={visible}
        onOk={() => setVisible(false)}
        onCancel={() => setVisible(false)}
        // This was removed
        // width={'1000'}
      >
        <p>some contents...</p>
        <p>some contents...</p>
        <p>some contents...</p>
      </Modal>
    </>
  );
};

ReactDOM.render(<App />, document.getElementById('container'));
  1. 您需要将这些 CSS 规则添加到 CSS 文件。

index.css

.ant-modal, .ant-modal-content {
 height: 100vh;
 width: 100vw;
 margin: 0;
 top: 0;
}
.ant-modal-body {
 height: calc(100vh - 110px);
}