How to auto-center jQuery UI dialog when resizing browser?

前端 未结 6 1265
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 07:44

When you use jquery UI dialog, all works well, except for one thing. When the browser is resized, the dialog just stays in it\'s initial position which can be really annoyin

6条回答
  •  心在旅途
    2020-12-04 08:12

    Another CSS-only option which works is this. The negative margins should equal half your height and half your width. So in this case, my dialog is 720px wide by 400px tall. This centers it vertically and horizontally.

    .ui-dialog {
      top:50% !important;
      margin-top:-200px !important; 
      left:50% !important;
      margin-left:-360px !important
    }
    

提交回复
热议问题