Simply Put the agency blog

Vertically center content with CSS

January 31st, 2008 by Verne

A convenient benefit of using tables is the ability to vertically center content within a cell using the valign attribute. Unfortunately, acheiving the same effect with CSS isn’t so convenient. So, as we continue to move towards tableless structures, there comes a need for a simple and valid CSS alternative. There have been a number of ways to approach this feat, but in this tutorial, I will lay out the technique we use to vertically center content using CSS.

The HTML

Three divs are required in order to pull this one off. Here’s an example of how we setup the divs.

<div id="container">
<div id=”position”>
<div id=”content”>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec laoreet egestas mi. Aliquam erat volutpat. Aliquam erat volutpat. Suspendisse potenti. Suspendisse potenti. Vestibulum mi nibh, hendrerit nec, feugiat vitae, feugiat a, nisl.
</div>
</div>
</div>

The #container div is used as the main reference point for centering the content. In other words, the content will be vertically centered against the height of the #container div.

The #position div is used to, naturally, position the content.

Finally, the #content div is used to encase the actual content that we are trying to center. This div is also used to correct the positioning of the content for Internet Explorer users (as you’ll see later).

The CSS

Here’s the CSS we apply to make it all come together:

<STYLE type="text/css">
#container { width: 100%; height: 100%; display: table; }
#position { display: table-cell; vertical-align: middle; width: 100%; text-align: center; }
</STYLE>

We’ve defined the height of #container to be the full height (100%) of the page. We could have just as easily given it a fixed height such as 500px. We’ve also added display: table and display: table-cell to #container and #position, respectively, which will tell it to mimic the properties of <table> and <td>.

You’ll notice that we haven’t applied any style to the #content div. This is because browsers like Firefox and Safari are able to use the uber handy vertical-align: middle property, making it almost just as easy as using tables. Using only the code we’ve shown thus far, our content should be nicely vertically centered on the page in all browsers except Internet Explorer, which doesn’t understand vertical-align: middle.

To correct this problem and ensure that our content is still vertically centered for IE users, we’ll apply the following conditional statements and extra bits of CSS.

<!--[if IE]>
<STYLE type="text/css">
#container { position: relative; }
#position { position: absolute; top: 50%; }
#content { position: relative; top: -50%; }
</STYLE>
<![endif]–>

The <!--[if IE]> … <![endif]–> tags tell the browser to only process this CSS if the browser being used is Internet Explorer.

When processed, the CSS places the top margin of the #position div halfway down the height of #container. However, this only places the content in the lower half of #container. So, to center it vertically, #content’s top is offset by -50%. That is, it is being shifted upwards a distance that is equal to 50% of its height. If you do the math and crunch the numbers in your head, you’ll find that this does a nice job of centering the content.

Live Demo

A live demo of this tutorial is available here. You can also download the demo page for your reference.

51 Comments

Tags: ,

Prologue: the company twitter

January 29th, 2008 by Verne

The folks over at Automattic (the same brilliant minds that brought us WordPress, Gravatar, and a number of other web apps) have unveiled their latest creation: Prologue. It’s not exactly a new project, but a highly customized WordPress theme that takes the concept of Twitter and mashes it into an innovative new way to stay connected with members of a group/company. And all within the friendly realms of WordPress.

Its use is not limited to being a company communication tool, but that idea had by far gotten me the most excited. Here at Vdot Media, it’s hard to stay on top of what everyone is working on, and while we’ve tried internal blogs and other tools, Prologue may serve to be the simplest and least demanding/involving solution (a characteristic that makes Twitter the lazy blogger’s best alternative). I just might be curious enough to try to see if this one will work out.

Aside from the productivity benefits, Prologue gets my two thumbs up for taking something with simple functions (WordPress) and hacking it up to do something completely different and something completely awesome (for lack of a better word). This kind of innovation really drives our team, and it’s what made Can’t Wait for Christmas such a fun project.

I’d love to hear from others who have tried out Prologue as a company communication tool. If the team will let me, I just might have a few first-hand thoughts to report as well.

In the mean time, read up on and see a screenshot of Prologue here. Download the theme and take it for a spin here.

Leave a Comment

Tags:

Farewell, IE6

January 22nd, 2008 by Verne

Internet Explorer 7It is with great sadness but greater joy that I share the news that IE6 will finally be put to rest come this February. According to InfoWorld, Microsoft has finally given the thumbs up to an autoupdate of IE6 to IE7 which is set to occur on February 12.

As web designers, we’re constantly kept awake at night fighting crime in the war of browser compatibility issues, hoping only to build websites that deliver consistent experiences to all users regardless of their browser of choice. Microsoft did us all a favour with the release of IE7 not too long ago, marginalizing the differences in how it displays websites between it and its next leading competitor Firefox. But despite this and all the new features and innovations that IE7 brings to users, there still remains a significant portion of internet users who haven’t been incented enough to make the leap from IE6 to IE7. This essentially has meant that the designers who choose to make accomodations for outdated users must design websites for 3 very different browsers. Until now, that is.

On February 12, the update will roll-out and a good 30% of the internet population will see many websites in a whole new light and in the way they were truly designed to be seen (despite our greatest efforts, many websites are still not fully cross-browser compatible). For us, it means the old ‘tester’ computer that still runs IE6 may finally be unplugged. Coincidentally, its power supply died last week.

You can read the full article on InfoWorld here. For the truly stubborn, the article also mentions ways to avoid the autoupdate.

This is great news for the community, and it comes shortly after the announcement of another exciting IE milestone. It’s definitely a good time to be a web designer.

2 Comments

Tags: , ,

Fake PR

January 15th, 2008 by Rami

Fake PRThe other day, I came across a black hat SEO technique that lets webmasters increase their page rank almost instantaneously. A good chunk of the webmasters know about this, but there’s a big group of those who don’t know anything. Let me explain.

One driving factor of SEO is link building, and we all know that getting links from high PR websites is key. The way fake PR works is simple: If you visit page X with PR 2, typically, a PR checker will show PR2 (for e.g. PageRank bar on a Google tool bar). If you visit page Y with PR 8, then the PR checker will show PR8. Simple, but now imagine if, when visiting page X you are immediately redirected to page Y. Or in other words the page that is actually being checked is page Y, then the PR checker will read PR8 and not PR2. Simply speaking, this is how the fake PR technique works. The technique redirects Google bots from page X to page Y while keeping the user on page X. When the Google bots are redirected to page Y, the bar for e.g. will read PR 8 (that of page Y), because that’s the page Google thinks you are viewing.

Before you get too excited and start redirecting Google bots crawling your site to sites with higher PR, it may interest you to know that this technique does nothing in terms of SEO. It doesn’t improve your rankings, and worse yet, by redirecting the big G’s spiders to another page, you hurt your chances of being picked up by Google properly. However, with the increasing demand for in-bound links from high PR websites, webmasters are using this technique to trick clients into thinking they are purchasing quality links to their websites. It’s easy for someone to fall for this, because when you visit the prospective website you simply trust the Google PR bar on the top. And when you’re offered a PR8 in-bound link for just $15, you’re just taken by it. You have no reason to doubt the PR bar, the price is great, and you don’t want to pass up the chance - so you pay for the link without giving it a second thought.

For the skeptical and the worried, I’ve luckily stumbled upon this Fake PageRank Detection SEO tool that should save you guys and girls some grief. Give it a try the next time you’re making an investment based on the PR of a website to make sure you’re not falling prey to fake PR tactics.

1 Comment

Tags: , ,

Site of the Day

January 9th, 2008 by Verne

I woke up this morning with a pleasant surprise - our site (www.vdotmedia.com) was chosen to be Site of the Day over at The Daily Slurp! In addition, our new has also been featured over at CSS Mania, Most Inspired, and CSS Creme - all popular website galleries that celebrate and showcase modern websites designed and developed in valid CSS/XHTML.

Site of the Day

Aside from the great exposure from being featured on the front page of these high-traffic sites, these galleries are a great tool for designers to find inspiring work from all around the world. I encourage everyone to give them a browse (and vote for our site while you’re at it!).

2 Comments

Tags:

Page 2 of 3«123»