【问题标题】:making antd modal full screen without any padding or margins使antd modal全屏没有任何填充或边距
【发布时间】:2021-05-06 20:10:49
【问题描述】:

我是编程新手。在这里,我有一个 antd modal,我一直在尝试找到一种方法让它全屏显示。我希望模态在打开时是全屏的,它不应该有任何边距或填充。比如我在代码中添加了width={1000},但是modal的左右两边还有一些边距。

那么如何使模态框占据整个屏幕而没有任何边距和填充?

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

【问题讨论】:

    标签: javascript html css reactjs antd


    【解决方案1】:
    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);
    }
    

    【讨论】:

      【解决方案2】:
      1. 你需要取消设置max-widthmargin的modal
      .ant-modal {
        max-width: unset;
        margin: unset;
      }
      
      1. 您需要在beforeant-modal-centered 类的伪元素中取消设置content
      .ant-modal-centered::before {
        content: unset;
      }
      

      工作Demo

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-09
        • 1970-01-01
        • 2014-03-05
        • 2015-06-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多