Centering a div vertically & horizontally using jQuery

后端 未结 9 1329
轮回少年
轮回少年 2020-12-02 08:44

I am using this script to center my div horizontally and vertically.

When the page loads the div gets centered vertically, not horizontally until I resize the brows

9条回答
  •  感动是毒
    2020-12-02 09:04

    I use this JQuery.center plugin to center my DOM elements. The code will be something like this:

    $("#child").center()
    

    The prior code will center relative to its direct parent, if you need to center relative to another parent, it will be:

    $("#child").center($("#parent"))
    

    There are customized options, if you need other form of centralization.

提交回复
热议问题