Articles for Tag: tutorial

Pseudo Pseudo-Classes

Some of the most powerful CSS2 and CSS3 selectors defined in the specs are avoided by web developers because they’re not supported by commonly used web browsers. Sometimes in order to work around these shortfalls solutions with large overhead such as javascript libraries are used or code becomes littered with many specialized classes and sites become difficult to maintain.

Over time I’ve developed the habit of using specifically named class attributes to represent exactly where a pseudo-class would have applied. To aid in clarity and maintenance these classes are named with the same text as the name of the pseudo-class being represented:

  • :first-child becomes .first-child
  • :last-child becomes .last-child
  • :first-of-type becomes .first-of-type
  • :nth-child(odd) becomes .nth-child-odd
  • :only-child becomes .only-child
  • :empty becomes .empty

And so on.

Your Typical List of Links

Some of these classes I use on every site I build. First-child [or last-child] are particularly handy when dealing with horizontal lists or menus where you want different delimiters or padding around the items on the edges vs the items in the middle of the list. A simple example would be to use vertical borders to separate the items. If you put a left border on all of the items you need to find some way to not have a border on the left most item. In a perfect world the HTML and css would looks something like this:

ul li { float:left; padding: 0 1em; border-left: 1px solid black; }
ul li:first-child { border-left: none; }
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="page2.html">Page 2</a></li>
<li><a href="page3.html">Page 3</a></li>
</ul>

Leaving no extra classes in the HTML at all. However, if your project must support browsers that fail rendering the above styles you’d update the HTML and CSS with the following simple additions:

ul li { float:left; padding: 0 1em; border-left: 1px solid black; }
ul li:first-child,
ul li.first-child { border-left: none; }
<ul>
<li class="first-child"><a href="index.html">Home</a></li>
<li><a href="page2.html">Page 2</a></li>
<li><a href="page3.html">Page 3</a></li>
</ul>

Remember, the class you’re adding should always represent exactly how the real pseudo-element behaves and thus the placement of the first-child class is important. For example you would not want to write the following HTML:

<ul>
<li><a class="first-child" href="index.html">Home</a></li>
<li><a href="page2.html">Page 2</a></li>
<li><a href="page3.html">Page 3</a></li>
</ul>

Even if you could style this example and the previous example to appear alike the danger is in the details. If in a later site revision you replaced the class selectors with the real pseudo-class selectors you’d wind up with totally different styling — in fact the pseudo-class version would apply to all the anchors in the list because they’re all first-children of their respective parent list item.

Legibility and Maintenance

Tossing classes into the HTML to have more ‘hooks’ to style with is nothing special. The key to these pseudo pseudo-classes working is the use of established names and established behaviors. Any developer can look at an element with class="first-child" and know exactly what it represents. Usage of words like “first” or “linkA” or “item1” might be used in the same ways, but they might not evoke the exact same meaning. Perhaps the “link1” is the first link, but it may not be the parent elements first child. Or perhaps one project will use an “even” class on alternating list items, where another might call them “off” or “alternate”.

So there’s power in the distinction between “linkA” and “first-class” and there’s time saved by setting coding standards up front.

What about Pseudo-Elements?

CSS3 pseudo-elements are a bit trickier to duplicate by using using class attributes alone. But the principle of standardizing on the use of class names that are similar to the items they’re replacing. If I wanted to stylize the first letter of a paragraph in some special means I’d use a css selector such as p span.first-letter {} and the necessary HTML to match instead of picking some other class name out of thin air.

Remember, the goal of pseudo pseudos is that there is a predefined behavior that you wish you could leverage, and you’re just looking for a way to duplicate that behavior in older browsers with the minimal amount of overhead and maximal amount of clarity and simplicity.

Further Reading

Geotagging Photos With Cell Phones Or Other GPS Devices

While some cameras and camera phones have the ability to geotag digital photos as they’re taken, most still don’t. However you can still geotag your photographs accurately and automatically with the use of an external GPS enabled device like a cell phone, navigation device, or a dedicated GPS logger. Any device that can record a “GPS track” that can be transfered to your computer can be used to tag photos. And photos taken with any digital camera can be tagged in this manner.

Here I’ll explain how I use GPSPhotoLinker on OS X to batch tag many photos from a day’s photo shoot with GPS tracks recorded on either a Sony GPS-CS1 or a Nokia N95 cell phone in order to create mapped photo galleries, like this one on Flickr.

Flickr maps screenshot

Recording Tracks

The Sony GPS-CS1 is a device made specifically for logging GPS points for use in geotagging and attaches to your computer via USB. To start recording a track you just turn it on and to stop you turn it off. While its on it will record a log file containing points every 15seconds in a format called “NMEA sentences”.

The Nokia N95 is a higher end cell phone with built in GPS and the ability to install applications. The 3rd party location recording application I’ve found is called GPSed. Like the dedicated Sony device, while the application is running it records a log of points that can be transfered to your computer later via USB. Unfortunately, it writes logs are in a custom format that have to be uploaded to their web site and then exported into a variety of formats.

Other GPS devices like those from Garmin will work much the same way as described above — just follow the manual’s instructions on recording the tracks and downloading them to your computer.

There are many different geotagging applications on the market here are a few for OS X compared but I’ve settled on using GPSPhotoLinker because I don’t need some of the extra features like tagging via drag+drop or looking at images on maps. My desire is simply to sync the geo data with the photos and then get on with the rest of my workflow.

Converting tracks for use with GPSPhotoLinker

GPSPhotoLinker is great application, but its main limitation is that it only reads GPS tracks in 2 standard formats: GPX or TCX, which means that you may often have to convert the output of your GPS logger into something that it can read. For the tracks recorded with GPSed I can just download the exported tracks in this format, but for the Sony tracks in NMEA sentence format I’ll need another free application: GPSBabel and its companion GUI, GPSBabel+.

GPSBabel+ screenshot

GPSBabel+ can be used to quickly convert from a large variety of different geo data formats into GPX files that can be loaded into GPSPhotoLinker.

Batch updating photo EXIF & IPTC metadata

Once the images are on the computer and the GPS tracks are in GPX format both can be loaded into GPSPhotoLinker where all images can be updated at once with its batch processing tools. The settings I use to update the photos can be see in the following screenshot.

GPSPhotoLinker screenshot

What next?

After the individual photos are tagged I then work with them as I would any other photo. I import them into Adobe Photoshop Lightroom where I add text based tags, adjust colors and other image settings, ultimately choosing some for upload to Flickr or printing service. No additional intervention is needed to ‘use’ the results of the image tagging process — the metadata is visible in Lightroom where I can click it and see a google map location, and images uploaded to Flickr with this geodata are automatically placed on the map for me.

Lightroom metadata panel screenshot

Quick Workflow Recap

  1. Download photos and GPS tracks to my computer
  2. Convert GPS tracks to .gpx with GPSBabel+
  3. Load photos and .gpx file into GPSPhotoLinker and batch process them
  1. Import photos into Adobe Photoshop Lightroom, or similar aplication and get on with the image processing

Some additional notes and hints

  • Be sure to keep GPS device and camera time settings in sync.
  • I’ve found its best to pause your movement for a moment and check that the tracking device has a signal when shooting for most accurate results.
  • GPSPhotoLinker updates IPTC fields with location data it receives from terraserver-usa.com, unfortunately I have found this information to be quite flaky, particularly when in an area that cannot be tied to a specific municipality [resulting in often occurrences of NJ locations written as being in NY]

Devices and Downloads mentioned in this article