Online Portfolio and Resource Blog Online Portfolio and Resource Blog


CSS: Center a Div Using Absolute Positioning

02Nov 2011

Aligning divs to the center of the page is relatively easy. It’s just a matter defining its width and setting the left and right margins to “auto”. Easy does it. But what happens when your div is using absolute positioning? It won’t matter if your left and right margins are set to “auto”. I have found a simple solution that works like a charm!

HTML structure:

<div id="main">
    <div id="header"> Header </div>
    <div id="content"> Body </div>
    <div id="footer"> Footer </div>
</div>

CSS: Positioning the “main” div:

#main {
    width: 960px;
    background: #f1f1f1;
    color: #000;
    text-align: left;
    position: absolute;
    top: 0px;
    left: 50%;
    margin-left: -480px;
}

The left position is set to 50% so that the div will begin at the center of the screen. The left margin value is -half of the size of the div we are centering. This pushes the div over to the left directly to the exact center of the page.

Click here for the final result

John-Hirchak.com Has Been Launched

09Oct 2011
John Hirchak - Online Portfolio and Resource Blog

My portfolio site has now been launched. Click Here

Photoshop: Creating Favicons Inside Photoshop

05Oct 2011
Photoshop - Create Favicon (.ico) Files

Photoshop - Create Favicon (.ico) Files

You can create favicons (.ico files) directly inside Photoshop by downloading the appropriate plugin at:
http://www.telegraphics.com.au/sw/product/ICOFormat#icoformat

Web Development: Creating 404 Error Pages

28Sep 2011
404 Error Tutorial

404 Error Tutorial

A 404 page is a necessity for any professional website. As files are updated and shuffled around, there is no guarantee that search engines will be up to date with your most latest changes. By creating a 404 page, you are keeping the user experience constant throughout the entire website, even if they happen to run across a file or page that is missing.  (more…)

CSS: A Set of Margin and Padding Classes

23Sep 2011
HTML/CSS Tutorial and Resource

HTML/CSS Tutorial and Resource

I no longer add margins or padding to block level/inline elements. Instead, I use the following set of classes to space my content vertically. I think this goes perfect with the 960 grid that I am using. Feel free to add more. (more…)