Centering a Website – Cross Browser

Most sites these days are centred and have a fixed with be it 800, 1024 pixels wide or whatever.  If any of you have used divs and css and tried using standard centering you might have, at one stage or another, scratched your head while viewing it on different browsers.

Let’s say we want a webpage with a width of a nice round 1000 pixels. To do this we might create a new div within the body tag called page:

<body>
<div class="page">Content goes here<br/><br/><br/><br/><br/></div>
</body>

In order to centre this on IE7 and less we simply set the width in the div and in the body tag set text-align to center i.e.

body
{
 text-align: center;
}
.page
{
 width: 1000px;
 text-align: center; /*don't forget to reset alignment for child elements*/

}

On IE8+, Firefox and other browsers this is not correct behaviour however and they will left align the inner div, therefore we need to centre the inner div using the margin tag by setting it to margin: 0 auto e.g.

body
{
 text-align: center;

}
.page
{
 margin: 0 auto;
 text-align: left;
 width: 1000px;
 background-color:red;

}

By specifiying margin: 0 auto and by setting the div’s width, the browser can calculate how much distance to place between the left side of the div and the left margin of the browser window.

So there you have it, simple and effective and cross browser compatible.

Flash Caching Issue on IE

I had a problem with a client of a client whereby they had a flash gallery component called simpleviewer on the site.  Basically depending on the page the browser viewed, the component would load up a dynamic xml file and present a different slideshow on each page.

The problem happened when users have caching turned to automatic.

I tried various things like, setting the various meta tags for browser caching in the head section of the html document

<META HTTP-EQUIV="Expires" CONTENT="0">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">

I tried setting this in the footer also because of IEs caching problem.

I then tried setting this sort of stuff on the server through php headers even setting the last modified date:

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header ("Last-Modified: " . gmdate ("D, d M Y H:i:s") . " GMT");

I then tried setting parameters on the .swf file itself hoping that it would see it as a new request for a different swf file each time (where contentid is the id of the page loading).

var fo = new SWFObject("viewer.swf?unique=<?php echo $contentid ?>",
"viewer", "640", "380", "8", "#ffffff");

In the end i figured out that the flash file itself was caching the xml document that it was loading  so this had to be different for each page request (I had been using cookies to store the currently selected page). 

fo.addVariable("xmlDataPath",
"gallery.php?contentid=<?php echo $contentid ?>");

And low and behold, problem solved.

Talk about beating about the bush!

Anyway, hope this helps someone else out there.

Sensible Link Building Strategy

Here is an interesting blog from the Google Webmasters Blog: http://googlewebmastercentral.blogspot.com/2010/06/quality-links-to-your-site.html.  Anyone interested in SEO should read the article carefully.

Here is a summary of the points made in the article:

  • Promote within your particular community and CONTRIBUTE to blogs and forums. This does not mean spam forums and blogs but actually share your knowledge and experience with the community.  Solving problems for people is a great way of doing this.
  • Use of humour can be good to get lots of hits quickly but that it shouldn’t be relied on as a long term strategy.
  • Beware of low quality directories and link sharing with random sites, these will ultimately damage your sites reputation
  • Another great tip is to make linking to your site easy through social bookmarking tools

So if you have quality link backs in mind, start sharing your knowledge today.

The New Google Keyword Tool

Last week I tried using the Google Keyword tool and it wasn’t working the way I expected it to and I thought to myself that this was the end of an era.

How could I survive without the trusted Google Keyword Tool?

Thankfully, when I logged in today it seemed to be back to normal with an improved interface.

For anyone that doesn’t know at this stage, the Google Keyword tool is an indispensable application for anyone who wishes to do keyword research on-line.  The tool allows you to put in a keyword or phrase and it will show you how many people search for this word/phrase and variants of it worldwide and also locally (i.e. your target area) for the previous month.  It also gives an indication of how many advertisers are paying for advertising off the back of these key words and phrases.

This information is critical to anyone who wishes to promote their site online.

From a Search Engine Optimisation point of view it facilitates decision making on what names to give pages on a website, what keywords and phrases to put on them etc.  I mean there’s no point in creating a page with a certain title if nobody is ever going to search for it.

It now also asks for a website address as well as a key phrase, which can be very handy to see what your competitors are up to as regards keyword targeting.

It is an invaluable tool for anyone who takes their on-line presences seriously.