Skip to Content


Public news / April 2006 / Centering Elements

Centering Elements

If you've ever become frustrated while trying to use vertical-align to place one element in the center of another element, we now have a solution!

permanent link 09 apr at 22:54 by Nick Gagne

There are 10 guest comments so far.

commentat 23:33 on 09 April 2006, Veracon wrote:

Decent article, but not at all news.

commentat 01:40 on 10 April 2006, Andy Social wrote:

A rebuttal.

commentat 02:00 on 10 April 2006, Nick Gagne wrote:

You should check it again. This method works in Internet Explorer too.

commentat 02:06 on 10 April 2006, Old News wrote:

Posted about 2-3 years ago

http://www.wpdfd.com/editorial/thebox/deadcentre4.html

commentat 06:55 on 10 April 2006, Nick Gagne wrote:

That method only positions it center to the window, if you have to scroll, then its no longer center. Try resizing your window down vertically until scroll bars appear.

commentat 14:04 on 10 April 2006, Kevin Cannon wrote:

It's interesting as a proof-of-concept, but practically speaking, I'd just use margins. It makes more logical sense and is less obtuse, which is good for maintaining CSS files.

commentat 16:03 on 10 April 2006, David B. wrote:

Andy did you start that site just to debate this article? wow and somebody sent ME and angry hate mail saying i needed to get a life ;)

commentat 17:24 on 10 April 2006, Nick Gagne wrote:

This method is meant for dynamic elements or multiple static elements of varying sizes. Suppose you have 10 images of varying size and you want each of them to be centered inside of a box, with all of the boxes having the same height and width, would you really want to set margins for each one of those?

commentat 18:27 on 10 April 2006, Andy Social wrote:

David, no I didn't start the site just to debate the article. In fact I never planned on using that domain to discuss CSS, but I did think it made for a good first post while bored on a Sunday afternoon.

Nick, I agree that your method is good for what you mentioned. As I said in my article, having to know the size of the image being positioned is definitely a drawback. There's always more than one way to skin a cat.

commentat 00:07 on 11 April 2006, Nick Gagne wrote:

I should have pointed out that this method is for images of varying dimensions, where you can't use margins or padding.

Add a comment:

(required, non-public)

  |  Chars left: 1000

Keep the comment relevant, constructive and be polite.
A valid email address or URL to your site must be provided, or the comment might get deleted. Content seemed inappropriate or offensive may be edited and/or deleted. Avoid explicit language and words such as "sucks" and "ripoff". For more in-depth discussions use our forum. Email addresses are never displayed. Line breaks and paragraphs are automatically converted - no need to use <p> or <br/>. Quotes & apostrophes are automatically converted to smart punctuation. Be careful when copying and pasting portions of entries or other comments. The following inline HTML elements may be used: <strong><em><pre><q><blockquote><code>. All other code will get removed before posting. Don't forget to close your tags.


Search the archive

Stylegala news archive

Public news archive

News contributors


Features

Stylegala BookStore
The Stylegala BookStore has a massive archive of great books for you as a professional..
Bullet madness
Bullet madness is a list of 200 bullets, arrows and icons uploaded by our users.
CSS Reference
An alphabetical list over the most common CSS1 and CSS2 syntax and properties.

Sponsors

Logo design for $149

Advertise here