How to design a CSS for a centered floating confirm dialog?

前端 未结 4 1576
轻奢々
轻奢々 2020-12-13 14:35

I\'m looking for a way to display a confirm dialog that\'s always centered on the page, and floating over the page.

Tried that, but it\'s not \'always centered\' at

4条回答
  •  不思量自难忘°
    2020-12-13 14:58

    Try using this CSS

    #centerpoint {
        top: 50%;
        left: 50%;
        position: absolute;
    }
    
    #dialog {
        position: relative;
    
        width: 600px;
        margin-left: -300px;
    
        height: 400px;
        margin-top: -200px;
    }
    

    #centerpoint should be the container div of the dialog

    Note that the #centerpoint DIV should be inside the body element or inside elements that don't have a position: relative; property

提交回复
热议问题