I've used a jQuery script I found to vertically center some content on a page I'm designing.
It works fine on all of the pages apart from the main index linked above. On first load, and even if refreshed, it's not quite centered. However, if I browse to another sub-page, and then click the "home" icon, it centers perfectly.
Does anyone have any ideas what might cause this?
Probably has to do with the script. A much easier way would be to take the height of the div in px, divide that by half, then do like so:
height:##px; /*height of the div*/
width:##px; /*width of the div*/
margin-top:-##px; /*negative half the height of the div*/
It's essentially the same thing the script is trying to do automatically, but somehow failing at.
The home page looks centered to me, but you have different HTML/CSS for the home page. The home content are in a div called #content_index, while other pages have #content as the content wrapper.
That's indeed a technique that one can use quite often. But not always, because the height of the to center object must be known and set. That is not always the case. And sometimes there are simpler techniques. For all five -- intuitive and valid -- techniques, including a flowchart to determine which technique must or can be used, see the tutorial Vertical Centering in CSS.
This topic is now closed. New replies are no longer allowed.