【问题标题】:Center Align Modal ReactJS居中对齐模态 ReactJS
【发布时间】:2021-09-06 16:49:25
【问题描述】:

我正在尝试在 ReactJS 中设置模式的样式,并希望得到一些帮助。我在尝试将内容模式居中对齐时遇到了困难。另外,在样式化模态时,是否可以在css页面中分配一个className并对其进行样式化?我试过这样做,但它不起作用。所以我只是决定做内联样式,但我不能居中对齐我的模态。

            <button onClick={()=> SEOsetModalIsOpen(true)} className="viewmore">
                View More
                <ArrowIcon className="arrowright"/>
            </button>
            <Modal
              isOpen={SEOmodalIsOpen}
              shouldCloseOnOverlayClick={true}
              onRequestClose={()=>SEOsetModalIsOpen(false)}
              style={{
                  overlay: {
                    position: 'fixed',
                    top: 0,
                    left: 0,
                    right: 0,
                    bottom: 0,
                    opacity: 1,
                  },

                  content: {
                    position: 'absolute',
                    width: '500px',
                    height: '300px',
                    top: '200px',
                    left: '500px',
                    right: '500px',
                    bottom: '200px',
                    border: '1px solid #ccc',
                    background: 'blue',
                    overflow: 'auto',
                    WebkitOverflowScrolling: 'touch',
                    borderRadius: '4px',
                    outline: 'none',
                    padding: '20px'
                  }
              }}
              >
              <h2>Search Engine Optimisation</h2>
              <p>Hello World</p>
              <button onClick={()=>SEOsetModalIsOpen(false)}>Close</button>
            </Modal>
            </div>

【问题讨论】:

    标签: css reactjs modal-dialog popup center-align


    【解决方案1】:

    您可以使用它以绝对定位居中:

    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    

    【讨论】:

      【解决方案2】:

      您可以设置而不是设置topleftbottomright 以使您的内容居中

      {
        display: "flex",
        justifyConent: "center",
        alignItems: "center",
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-11-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-25
        • 2017-05-15
        • 1970-01-01
        相关资源
        最近更新 更多