Search code examples
javascripthtmlcssreactjsantd

making antd modal full screen without any padding or margins


I'm new to programming. Here I have an antd modal and I've been trying to find a way to make it full screen. I want the modal to be full scree when it's opened and it shouldn't have any margin or paddings. For example, in the code I added width={1000} but there is still some margin on the left and right of the modal.

So how do I make the modal to take the whole screen without any margin and padding?

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


Solution

    1. Remove the fixed value for modal width and the centered attribute from your code file:

    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. You need to add these CSS rules to the CSS file.

    index.css

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