Absolutely Center Any Element With CSS & jQuery

As a front-end developer, you’ll often times run into a situation where you need to absolutely center an element. Unfortunately, CSS doesn’t really give us an easy solution. Sure, if you want an element centered horizontally that’s pretty easy. We can do something like:

#element { margin: 0 auto; }

Or if you’re working with an in-line elements you could use:

#element { text-align: center; }

That’s all fine and dandy, but what if you need something smack-dab in the center?

The CSS Technique

Positioning an element in the absolute center can be accomplished with CSS. In order to do that you will need to know the following:

  1. The height and width of the element you want centered.
  2. The height and width of that element’s parent container.

Continue reading

Share in top social networks!

placeMe.js – A Placeholder Polyfill

UPDATE: Development for placeMe.js has moved to https://github.com/mattsparks/placeMe.js

One of my favorite new attributes in the HTML5 Spec is the placeholder attribute. This new attribute allows us to easily add placeholder text to our input fields. When the input field is focused upon, the placeholder text is removed.

<input type="text" placeholder="Please enter your name">

This has been a standard feature on the web for quite sometime, usually being accomplished with JavaScript. With the introduction of the placeholder attribute, the browser takes care of the job for us.

Of course not every browser supports the placeholder attribute. While most modern browsers do (Firefox 4+, Chrome 4+, Safari 4+, Opera 11.6+), Internet Explorer does not.

I wanted to use the placeholder attribute without fear so I wrote a little polyfill using jQuery. I’ve decided to call it placeMe.js and give it away to anyone who would like to use it and/or improve upon it.

How to Use

First include jQuery

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

Next include placeMe.js

<script type="text/javascript" src="/path/to/placeMe-0.1.js"></script>

Now use the placeholder attribute to your heart’s content

<input type="text" placeholder="This is my awesome placeholder">

Download

This is my first attempt at writing a polyfill, so be sure to let me know what you think in the comments.

Share in top social networks!

The Ultimate List of IE6 Fixes & Hacks

August 27, 2001. For web developers, that is a date that will live in infamy. On that unassuming August day, Internet Explorer 6 was officially released. No one could have foreseen the headaches IE6 would cause for developers. Who could have known that in late 2009 Internet Explorer 6 would still have 12.1% market share, forcing us to make sure our sites play nice with it. There have been many attempts to bring down our foe (here’s one, here’s another), but alas, IE6 won’t go down quietly.

IE6′s problems are well documented, but luckily for us a lot of smart people have found ways fix (or side step) those problems. Here is a huge list of hacks, fixes, and resources to make IE6 a little less painful.

IE6 Box Model Bug

More than likely if you’ve heard of only one IE6 bug, the box model bug is the one. In short, IE6 incorrectly calculates the width of a given box causing all sorts of layout problems. Here are some ways around this annoying bug.

Continue reading

Share in top social networks!