Self Clearing Floats

June 6th, 2008

The ‘clearfix’ or self-clearing method as published at Position is Everything, is my favorite method for clearing floated elements. My only quarrel with it is that it requires you to add the class ‘clearfix’ (or whatever you have renamed the class to) to the parent container of the floated elements. While this is not such a big deal if you only have one or two containers that require the class, it can quickly get unwieldy in a document that has multiple containers embodying floated elements that need to be cleared.

My preferred method is to add the necessary clearfix rules to each element as needed in the external CSS file. It helps reduce ‘classitis’ and keeps the HTML document from getting cluttered with extra class names that have no structural meaning.

For example, if there were, say, 5 divs that needed the clearfix technique, we would apply the following rules to our style sheet:

#div1:after, #div2:after, div#3:after, div#4:after, div#5:after {
	content: ".";
	display: block;
	height: 0;
	clear: both;
	visibility: hidden;
}

And we’re done! Well, that is if we don’t plan on supporting IE6 or IE7. Those two browsers require some additional rules to cooperate because we need to trigger hasLayout for the auto clearing to kick in. Fortunately, that’s pretty easy to do:

#div1, #div2, div#3, div#4, div#5 {
	min-height: 1%;
	display: inline-block;
}

min-height alone will do the trick in IE7, but it’s older sibling needs more help, which accounts for the display: inline-block; bit. The above should be included in our separate IE style sheet so that only IE 7 and below see it. This will keep FireFox 2 from chucking up errors in the console when it doesn’t understand the inline-block; rule we’ve applied to the global clearfix class, plus it has the advantage of keeping our IE hacks, filters, patches etc. from overriding anything in our master style sheet.

But, wait there’s more! If we don’t want to use the clearfix method and we STILL want a self-clearing element, we can also apply overflow:hidden; to the element shrink-wrapping the floats. One thing to beware of here though is that negative margins won’t work. I first discovered this handy trick courtesy of Jonathan Snook’s Top CSS Tips write-up.

In a similar fashion, setting overflow: auto; also seems to work. This technique can produce unwanted scrollbars if not used with care, so be on the look out for that. Alex Walker covers this technique in some detail in his article, Simple Clearing of Floats.

Ultimately, there are lots of options for clearing floats - usually the task at hand dictates the best technique. Call me old fashioned, but I still like to include a rule in my master style sheet that will apply to a non-semantic element in the HTML document, just in case I need it. You’ve all seen this guy before:

.clear {
	clear: both;
}

I keep him around in case the parent container of the floated elements experiences unwanted vertical margin collapsing. I generally use this pretty sparingly, but on a large site, it could turn up in the source code here or there, causing someone to poke me in the ribs and ask why it’s there. Now you know. And unless I’ve been misled up until now, knowing is half the battle.

Sometimes as front-end developers, we have to use a little necessary evil. When that happens, learn to forgive yourself and move on: your therapist will thank you.

Friday Afternoon Photo Op

May 30th, 2008

Eh, this probably seems inexplicably lame to the casual observer, but Teddy Ruxpin is something of a cult hero around the office. Maybe we just have too much time on our hands…

Opening External Links with jQuery

May 23rd, 2008

A tried and true use of JavaScript is to open external links in a new window (or tab, depending on your preferences). I’ve come across countless scripts written to do this task, and even though some are using jQuery or Prototype, they are not making the most out of the library or framework they are using.

Basically, there are three ways to open an external link in a new window:

  1. Give the a tag a class of ‘popup’, or something to that effect, iterate through the links and open those with class of ‘popup’ in a new window.
  2. Set the rel attribute to external, and again, iterate through the links in the document, find the ones that contain this attribute and value pair and open the links in a new window.
  3. Iterate through all the links in the document, check to see if the href contains the current site’s URL and if it doesn’t, pop it open in a new window.

For this example, I am going to assume my links are marked up like so:

<a href="http://google.com" rel="external">google.com</a>

With jQuery, there’s no need to iterate through each link and test for the rel attribute, and it exists, test for the value external. You can simply use CSS selectors to grab only the links you need without having to loop over them, then simply apply the Click Event Helper directly to those links like so:

$(function(){
	$('a[rel=external]').click(function(e){
		open(this.href);
		e.preventDefault();
	});
});

That’s what I like about jQuery - you get in, get what you need and get out. :)

Tripkick.com

May 15th, 2008

At Tripkick, we aim to take the guesswork out of your hotel experience. Not all hotel rooms are created equal, so we sought to devise an online concept which would deliver more choices to travelers.

Early Monday morning, Tripkick.com was unleashed to world.  Cédric, David and myself handled the code while Amanda Halbrook designed it to look beautiful. They’ve already been written up on TechCrunch and featured on NBC to much good praise, so a hearty congrats and a round of back-patting are in order for both Tripkick and Fluidesign.

Having recently started to travel more frequently to various web conferences, I have been thumbing through the hotels in the most frequented cities of the top conferences: San Francisco, New York, Austin and Boston. Because really, who DOESN’T want to avoid the dreaded ice machine and it’s guttural roar as it springs to life providing the much needed ice for my Champale?

I sure do.

brockandkristina.com

May 1st, 2008

Co-worker and friend Kristina has launched brockandkristina.com - a website dedicated to her ceremonious wedding later this year. Not enticed by most of the free wedding template sites, she cranked out a custom motif that draws its inspiration from the desert landscapes of Palm Springs, California.

As it turns out, not only is the site a good way to learn the back story of how she and her fiance Brock met, but it’s also a damn good resource for hotel and activity information for those planning a trip to Palm Springs.

All the coding was handled by yours truly. jQuery helped keep the Ajax call simple and also allowed me to use nyroModal, the highly customizable and flexible jQuery plugin from monsieur Cédric.

Users Were Born to Make Mistakes

April 25th, 2008

This morning, while trying to cure a rash of comment spam awaiting me in the moderation queue, I accidentally deleted all (but one) of my real comments along with the all the links to rapid weight loss pills and online poker.

Aside from feeling slightly stupid, I realized that no matter how well something is designed or implemented, someone is going to either a) make a mistake or b) find it counter intuitive. We do our best as designers and developers to make doing stuff online easier for our user base, but every now and again, someone like myself comes along and manages to screw it up. Shockingly, I am more than familiar with the WordPress admin section and I still managed to jettison my valid comments. I can chock that up to too many late nights banging away at the keyboard and too little sleep.

Sadly, my host is not running back-ups of MySQL at this time, so all those bright, shiny comments you all have left me are lost in the sands of time. Forever.

Fear not. You can begin commenting away anew.

Now I am little older, a little wiser and have a lot less comments on my site.

Moved

April 16th, 2008

As a minor housekeeping note, my blog has moved from the sub-domain blog.solidhex.com to the parent directory, www.solidhex.com. There should be no service interruptions and everything should redirect automatically as I have setup a 301 redirect in my htaccess file to ensure no broken links. If anything goes wrong, please let me know!

For the curious, this is what I added to my .htaccess file to get it to work:

RewriteCond %{HTTP_HOST} ^blog\.solidhex\.com [NC]
RewriteRule ^(.*) http://www.solidhex.com/$1 [R=301,L]

Therefore, the entire .htaccess file (with WordPress settings included) is:


RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^blog\.solidhex\.com [NC]
RewriteRule ^(.*) http://www.solidhex.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

I am not sure if that’s 100% accurate, but so far, so good!

nyroModal

April 13th, 2008

Designers seem to like using modal windows more and more, as they provide a quick way to show data without reloading the entire page. It’s easy to use and easy to design. The big problem I experienced with every plug-in I tried either using Prototype/Scriptaculous or jQuery is the customization. They say you can do whatever you want simply but that’s not true. The default CSS works fine, but most of time it’s a mix between required elements and optional. This mean you have to be very careful when editing it. The other problem is the animation. That’s the worst point. I never found one plug-in allowing to redefine easily the animations.

And with that, Cedric has relased nyroModal.

The seeds for this idea were planted as he and I continued to work on large sites utilizing many modal windows. Once you stop using them for simple login pages and image galleries, they can become quite a mess to customize.

Cheers to him for solving our problems and making it available for others to use.

Upgrade

April 8th, 2008

The other night, I upgraded to WordPress 2.5. The process was painless and quick, just like an upgrade should be. As everyone and their third cousin twice removed knows by now, the admin section was given a new swash of paint by the fine folks over at Happy Cog.

Had you asked me before I installed version 2.5, I would’ve said that the previous admin wasn’t broke so why fix it? Well, Happy Cog proved me wrong. Only after you give the new skin a test drive do you realize how cluttered its predecessor had become. As feature creep set it in over the years, it’s easy to forget that the primary focus of WordPress is publishing content on the web. 2.5 doesn’t bombard me with so much stuff up front, but everything I want and need is there waiting for me patiently should I decide to use it. It just feels, and I hate to use this word, streamlined.

I won’t go into an exhaustive feature or API list here, get that info direct from the horse’s mouth.

If you haven’t upgraded yet, I suggest taking the plunge when you get a chance. Just please make sure to make back-ups of your files, fer cryin out loud.

And the Tweaks Begin

April 5th, 2008

Slowly but surely, I am finally starting to make some tweaks around here. Firstly, I’ve updated the blogroll list, but I am taking (what I think) is a unique approach; I’ve either met or worked with everyone on my blogroll list at some point or another. I am doing this for two reasons:

  1. It will help me remember everyone I’ve met during the course of the year at conferences and meet-ups.
  2. It makes me look more important than I actually am.

And by met, I mean in person, face-to-face. I think this will encourage me to introduce myself to more people. In the interest of full disclosure, I basically stole the idea from Jeremy Keith’s bedroll. He takes it one step further by actually requiring a stay over night and a bouzouki serenade, but that’s more than I willing to extend myself at this juncture. Speaking of Jeremy, he is not yet on my list, even though I’ve had iChat conversations with him a couple of times and sat next to him at a panel or two, it’s not kosher per my strict sidebar-linking guidelines. For everyone else on my list, it’s a sure bet I’ve either talked geek with or work with them.

Other minor tweaks as well as vast re-aligns are coming shortly as I find time. But let it be said, I am really committed to improving this site. Where did all this zest and vigor come from? I’ve been a front-end web developer, full time, for the last four years at Fluidesign. I’ve been tinkering on the web for eight years. It’s been a long time since I’ve done anything other than client work. Plus, I want to give a little back to the web community at large if I can. I’ve learned countless time saving tricks and bug fixes from everyone else, and it’s high time I bring something to the table other than my own hungry, fat stomach.