Archive for February, 2008

I Hate Country Select Boxes

Friday, February 22nd, 2008

The country select box is my favorite pet peeve. You see it everywhere, in every signup form, every address entry form, everywhere that someone thinks that you’re too dumb to know what country you live in without some hints. Sure, you can tack USA to the top of the list, but where does that really get you? “Screw you Germany, France, Somalia, Canada, the UK, the Rebublic of Ireland, Russia, Croatia, Slovenia, Romaina, Bulgaria, and whatever other countries there are, you don’t have the internets anyway.”

The country select box isn’t an just insult to my intelligence and my nation’s internets-usage, it’s also a pain to use. I’ve learned to press “C” three times to get Canada, but I pity the poor fellow who lives in Myanmar and has to press “M” a grand total of 21 times to bypass Macau through Mozambique, and all the while dodging bullets fired at Buddhist monks. You know what country you live in, and you can spell it on the first try, too. So why have a select?

With some creative javascript, a small amount of input checking, and a bit of moxie, you can spare your visitors this humiliation. All you need is a list of all the countries (which you needed anyway), and a text input.

Here’s the HTML, to start:

<input type="text" name="myElement" id="myElementID"
onkeyup="countryList.updateTextbox(this.id,this.id+'_container')" />
<div id="myElementID_container"></div>

If you really want to be fancy/unobtrusive, you can rig up some javascript to apply the onkeyup stuff only when you load the page or something, but that’s not my point. Also, bonus points if you add onfocus and onblur attributes that show and hide myElementID_container.

I like to work with php, because I like having an extra layer where I can pull some fancy tricks to help myself out. In this case, that involves getting an array of every country. I used this one because it’s associative and gives country codes. Put it somewhere appropriate so that we can get at it. To get it into a form we can use from javascript, we simply invoke json_encode(), which will turn it into an object.

Next comes a wee bit of javascript, with the one thing of PHP. I’m going to make everything take place from within the context of a JSON object called countryList, because I feel fancy, and because if some other javascript needs a variable called countries somewhere else we won’t have to care. Here, I’ll walk you through it — if you just want to take the code without learning anything, that’s fine, but your punishment is that you have to copy each of my snippets individually to do it. Credit is always nice, too.

var countryList = {
	countries : <?= $countries ?>,
	updateTextbox : function(id, containerid){
		textBox = document.getElementById(id);
		current = textBox.value;
		var suggestionslist = document.createElement('ul');
		for(var code in countryList.countries){
			countryName.to = countryList.countries[code];

That part was pretty boring, I just instantiated everything and started my loop through the JSON. What happens next is that I’m going to use the substring function to compare the start of what I’m typing with that start of all the countries I’m looping through. Then, if there’s a match I’m going to use the DOM methods to build me a new list item featuring a link (clickable to update the textbox), to add to my new list of countries, replacing the old one.

	if(countryName.substring(0,current.length).toLowerCase()==current.toLowerCase()){
		countryNameNode = document.createTextNode(countryName);
		listNode = document.createElement('li');

		linkNode = document.createElement('a');
		linkNode.setAttribute("href","javascript: document.getElementById('"+id+"').value = '"+
		countryName+"'; countryList.updateTextbox('"+id+"','"+containerid+"'); void(0);");
		//The void(0); above is necessary to prevent firefox from redirection, annoyingly.
		linkNode.appendChild(countryNameNode);
		listNode.appendChild(linkNode);
		suggestionslist.appendChild(listNode);

	}

Next, we just append the list, after closing our loop, of course.

		}
		var container =document.getElementById(containerid);
		while(container.firstChild)
			container.removeChild(container.firstChild);
		container.style.textAlign = "left";
		container.appendChild(suggestionslist);
	}
}

And there you have it!

What’s that? “A demo,” you clamour? Fine, here. Note that this has a fancy timeout applied to the onblur hide so that you can still click the country links, if you’re quick enough.

If you use this, you should definitely add a check to see that the country is in a form you can use. Be sure to check for variations, e.g. “USA,” “The US,” “United States,” etc., but don’t be draconian about it or this will prove worse than a regular dropdown. Remember to be user-friendly, not user-proof.

Typography: Leading For Dummies

Thursday, February 21st, 2008

Or, The Magic Number 1.68

One issue in web design coming to the forefront recently is that of typography. Typography is defined by the Oxford English Dictionary as “The action or process of printing; esp. the setting and arrangement of types and printing from them; typographical execution; hence, the arrangement and appearance of printed matter.” We’ll just pretend that computers count as “printed matter”.

Today’s article on typography applies to spacing. To web designers, spacing can mean a lot of things, and proper typographic spacing can mean a lot of work. Well-typed documents often require the designer to obsess over details like vertical rhythm, line heights, header margins, grids, etc. It’s so much work that I’ve saved this post for a good long time until I could get around to typing this blog properly, so that I wouldn’t get complaints about it.

However, I’ve come up with what I consider a good standard for spacing, and as you may have predicted, the ratio 1.68 is central to it.

The Method

The first aspect of this scheme is to set the body font size, which I typically set to 83.5%. This allows ems to be treated as point sizes, such that 1.2em is equal to 12pt text. This is a matter of preference of course, but unless you do it this way your magic number may be different, so bear with me for now.

The total vertical space occupied by an element is the sum of its top and bottom margins and its line-height, as well as its top and bottom padding if applicable. 1.68 represents a good line-height for 12pt (1em) sized text, and a good top-and-bottom margin as well. So the way to start is to do this:

p{
font-size: 1em;
line-height: 1.68;
margin: 1.68em 0px;
}

This ends us up with 10pt paragraph font, and a vertical spacing of 3*1.68, whatever that is. Also note that the margins will collapse on top and bottom.

The next step in the process is to make sure that every block element in your body copy should have 1.68, or some multiple of it, intrinsic to its vertical spacing. This includes h1 through h6, paragraphs, list items, block quotes, and any other sectioned text that you have in your documents. This can be achieved by picking the font size you want, and then setting the line-height to that over 1.68. If you want 1.2em text, make your line-height 1.4. The top- and bottom- margins should be the same, in ems, as this.

Headers are a special case. They can have uneven top and bottom margins, as long as the sum of the top and bottom margins is a multiple of 1.68. The line-height for larger headers can double if they’re getting cut off, such as the headlines in my blog as of this writing.

After all that’s said and done, you will have a page with perfect (adequate) vertical rhythm. What does that look like? It looks like this template I made. Look at the sidebars, and notice that the text lines up with the body. If I had used a smaller font with appropriately larger spacing, such as 0.9 : 1.8666, it would still line up, and be a neat effect to boot. Try it!

I should mention I learned all of this from http://webtypography.net , whose advice is nothing short of exhaustive. If you found this even a little interesting, be sure to check them out.

Why isn’t my Negative text-indent hiding text?

Wednesday, February 20th, 2008

I’m making this post so that some day some person will google that phrase, and come here, and I can tell them that it might be because some parent element has a text-align: right set on it, which seems to render negative text-indents not at all.  Set the thing to text-align: left and everything will be ok.

Dress for Success

Wednesday, February 20th, 2008

That’s what my mom always told me. I never believed it — through high-school and well into college I wore almost exclusively second-hand clothes, save the first week or two on a job when I was trying to make a good impression. But I sometimes felt out of place, especially when I had to put on my not-so-well-worn suit and a tie and make like it didn’t feel strange. However, two months ago I placed an order at Indochino.com for a tailored suit, after having read about them in UVic’s student paper (The Martlet) several months prior. The suit came in two weeks, and as soon as I tried it on, I knew I had made a good decision.

Nothing looks quite so good as a properly fitted, stylish suit. You can’t slouch in a suit; you have to stand straight up, chest out. And I can tell you, when you know you look good, it really helps your confidence. I can’t tell you why, but if you’ve tried it you’ll agree with me.

Anyhow, a few weeks after that Indochino announce a sale, giving three free shirts with a suit or outerwear purchase. Having found that my usual vintage outerwear did my newfound business apparel no justice, I opted for a James Dean-esque peacoat, which proved to be another excellent purchase. I wear the shirts whenever they’re clean, and I always feel like I’m ready to take on the world, even when taking on the world involves not leaving the house.

In closing, I have two points. One, Indochino is worth checking out. I’ve had several contacts with the guys who run it, and they seem very down to earth and service-oriented, and the suits they sell look pretty sharp too.

Two, if you dress well, you feel good, and if you feel good, you live, work, and play better.  Of course, sometimes dressing well means my comfortable second-hand stuff, and that’s alright too.

Blog Design

Sunday, February 17th, 2008

This layout came to me as I was sitting around, bored, and started drawing in my notebook for something to do. There are many things I’m proud of, and many things about it that I don’t like too. I’d love to hear what anyone who happens to read this thinks about it, but I’ll start you off with a list of critiques.

No Title

Firstly, it has no title, and besides the context there’s no indication of its blog-hood. I guess the title is my name, but I should probably mention something else somewhere.

Basic Layout

The layout is sort of basic and done to death. Header bar? Check. 900px wide column? Check. White content background, with shadows on either side? Check. And the pixel-patterns like those in the background are quickly becoming a cliche. (No offense to freshview for being the only one mentioned. I’ve seen many sites with such patterns recently.)

And speaking of the shadows on the content section, if you try loading this page in IE you’ll see another problem - the transparent .png turns white. That’s just no good.

Mild Haphazardness

The footer could have had more work put into it, and from a marketing perspective I could have tied everything in a bit closer to my main web design site.

The header image is quite large, and it’s a bit confusing for the first few seconds while the rest of the page loads in a flash (I even indexed my .pngs to make them a few kb smaller - that’s how much I care.) However, the way it is it’s simply impossible to reduce, I’ve already posterized it as far as it will go.

The colors in general are quite bright, and were picked without any palette in mind.

And finally, I had meant to break the border to give the page a sense of wholeness rather than header | content, but I couldn’t figure out what to do it with.

Good Stuff

I don’t think I got it all wrong, though. The header is visually interesting, I think, and the brown background looks fairly sharp despite being a bit unoriginal. Also, the way the two images for the background (the repeating pattern and the darkening gradient at the top) will line up is a thing of beauty, given their small size.

Also, the design looks very much like what I sketched out. It’s always nice to be able to capture an idea well, even if you find out later that the idea wasn’t all it was cracked up to be.

Your Mission

Should you choose to accept it, you can do one or both of two things:

1) Tell me what you hate about this site.

2) Go do the same for your own site, and then come comment about that. I’d love to hear it.

The Case for Fixed Width

Saturday, February 16th, 2008

I’ve read a fair share of articles detailing liquid layouts, frequently using complex css techniques. However, when it comes to pages I make, I believe that fixed-width layouts are the best way to go for 99.9% of situations. Why?

Firstly, and somewhat selfishly, I say this because fixed-width layouts are easier to work with, giving you the ability to tweak the design to the pixel and have it display consistently. A liquid layout can produce unexpected effects on small screens. Fixed-width layouts display consistantly on small and large screens.

Fixed-width layouts force whitespace on the margins, which is never a bad thing. This isn’t to say that margin whitespace is not possible with liquid layouts, but with Internet Explorer 6’s incomplete support for min-width and max-width properties, fixed-width seems the best way to prevent your 80% wide page from shrinking to unreadable levels on smaller screens. In addition to the aforementioned lack of support for min-width and max-width, fixed-width layouts skirt IE’s strange treatment percentage-based widths and heights.

Another consideration: many users are using larger and larger screens. Therefore, a liquid layout will result in extremely wide columns. And, as any usability specialist will tell you, larger columns become quite difficult to read, especially on monitors that are 22″ or larger.

Of course, liquid layouts will always have their place. Although the average 1024-pixel-wide resolutions display the 900px layouts typical of my and many sites perfectly, smaller-than-average resolutions are still in use by some, and the popularity of the Asus EEE and mobile internet browsers will only increase this proportion. A simple workaround for this is, of course, to include an alternate stylesheet.

What say you?

Review: Aptana Development Environment

Monday, February 4th, 2008

I stumbled across Aptana quite by accident, while I was looking up some Ruby on Rails resources, as the beast formerly known as RadRails is now a part of Aptana. Aptana is built on Eclipse, which carries some good and bad news. Normally, I use PDT, Eclipse’s official PHP development framework. However, unlike PDT, Aptana provides editors for CSS and JS, superior HTML abilities, and its very own php editor.

The Good

Aptana supports html, css and javascript editing natively. It includes Subclipse as a supported plugin, and has plugins for PHP, Ruby (as discussed), and Adobe Air environments. It even does iPhone-specific development. Stability is not a major issue — Aptana is built on Eclipse, which is a very mature open-source project.

Aptana has a built in site manager, sort of like Dreamweaver’s, which will allow you to make updates to your local copy and then click “synchronize” for instant gratification. Unfortunately, I tend spread development between my laptop and my desktop rig, so the ftp synchronize can be deadly. I prefer to use Subversion to keep the two up to date with each other, then upload the changes from a third control directory that I always update before sending off.

The Bad

Eclipse, and by extension Aptana, is built on Java. Apologies to major users of Java, especially those who will tell me how wrong this is, but the jvm is, at times slowwwwww. However, this was alleviated somewhat by switching my Ubuntu setup to use the sun 6 jvm, instead of the gcj.

The Editors

Aptana contains four main editors that I use - the HTML, CSS, JS, and PHP specifically. Of course, all can be used in the same document without difficulties. Each contains the usual goodies that any IDE for anything ever has to have before it’s called an IDE: Error checking, syntax highlighting, autocomplete, and function lookups.

(more…)