With the development of one project, the diva positioning in the middle of the page arose regardless of the width of the diva and whether there is a scroll on the page.
If the page fits on the screen - you can do it through sss (position: absolute; left i top), but here you must take into account the width of the diva in each version.
If scrolling appears on the page - then there are some problems.
Since the last time (and in that project too) I use javascript framework jQuery - I decided to make it into a plugin.
This is how the positioning plugin appeared.
The plugin has 2 methods:
positioning (leftOffset, topOffset, scroll) - position the element on the page
leftOffset - horizontal shift
topOffset - vertical shift
scroll is a parameter that specifies the positioning relative to the “absolute” upper left point of the browser, or positioning relative to the upper left point of the already scrolled page.
')
The call centering () - positions the element exactly in the center of the page.
Plugin tested in FF 3.0, IE6.0 +, Safari 3.1, Opera 9.6
An example can be found here.
yablog.org.ua/jquery/index.htmlAt the bottom of the page there are 3 buttons - clicking on them you can see the plugin in action