mr_goosey — 2013-02-16T16:36:23-05:00 — #1
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?
ron_roe — 2013-02-16T16:43:18-05:00 — #2
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.
ralphm — 2013-02-17T00:23:39-05:00 — #3
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.
frank_conijn — 2013-02-17T08:16:21-05:00 — #4
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.