Center Page Vertically

Center Page Vertically

How do I center a page in a window vertically, without using returns or tables?

It’s easy to center the page horizontally–all you need to do is use the

tags. Centering it vertically is much more of a challenge. It can be done in IE4 with some work, but not with any Netscape browser.In order to center vertically, you need to know two things: the dimensions of the window you’re trying to center to, and the dimensions of the container. These values can be obtained using the clientWidth and clientHeight properties: the former on the document.body object, the latter on the division being used to hold the actual contents. I’ve written the VertCenter routine to actually do the resize.

Note the divLeft and divTop equations. The midpoint of a window or a div will be exactly half of the width. In order to determine where the left-hand side needs to go, I find the midpoint of the screen, move left and up (hence the negative sign) to the distance of the midpoint.

I pass a reference to the VertCenter function as an ID rather than a pointer because I wish to call it from outside of the DIV. Specifically, I need to catch the OnLoad and OnResize events for the page. This way, any time the screen is resized or reloaded, the div will center automatically.

Note that this doesn’t center the contents horizontally. If you wish to do that as well, you should place

within the encompassing DIV or LAYER.


Centering Verticallyis a little tougher

The center tag may not be the most elegant piece ofcode out there, but it does take care of handling the tediousjob of centering by hand. However, it doesn't support verticalcentering, making it exceedingly difficult to center an elementboth horizontally and vertically.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing