Death to the Bottom Line
Some creative nth-child()-ing. In a table-esque inline-block list, it will remove the extra line that results from needing both container and list item borders.
Why might this be useful?
- Rounded corners on container: setting a negative margin on list items in the top/bottom row leave the corners misaligned.
- Pixel perfection: using a negative margin on either the top/bottom borders of the list items sometimes shaves off a pixel, resulting in slight vertical-misalignments.
For this example, I’ll be using a 3-column layout using only inline-block list items. The three selectors used in combination to select the bottom row in all permutations are:

For this example, I’ll be using a 3-column layout using only inline-block list items. The three selectors used in combination to select the bottom row in all permutations are:

There’s a pattern/strategy here. Let x be the total number of columns. All we have to do is figure out how to select each list item when it’s on the bottom row, and deselect it when it’s not. Let’s try this with four columns:
- Select the last item, regardless of its position.
li:last-child - Select the next to last child, except when it’s in the rightmost column (where it’s not touching the bottom).
li:nth-last-child(2):not(:nth-child(xn)) - Select the third to last child, except when it’s in the two rightmost columns.
li:nth-last-child(3):not(:nth-child(xn)):not(:nth-child(xn-1)) - Select the fourth to last child, except when it’s in any column but the leftmost one.
li:nth-last-child(4):not(:nth-child(xn)):not(:nth-child(xn-1)):not(:nth-child(xn-2))
For additional columns, add another selector incrementing the nth-last-child() parameter, and add another :not(:nth-child(xn-?)), incrementing the ?.
Questions? Find me on Twitter and ask away! Or just view some working code on Dabblet.
A Clean, Minimal Bing
Google’s Search+ and GKBO antics have really rubbed me the wrong way over the last couple of days. So in retaliation, I’ve switched my default search engine to Bing.
It hasn’t been a frictionless switch. The quality of image results for certain search terms is mediocre. The results pages are cluttered, squished and chock full of distractions. To help the transition along, I made some tweaks to the design and encapsulated them in a user style. Most of the changes should be fairly obvious, but if you’re interested in a full changelog, I’d be happy to put one up.
To be honest, the exercise was more challenging than I expected:
Can’t stand cluttered Bing search. And after hacking away at it with Stylish, I can’t really stand the circa-2001 source code either. #fb
— Keith Chu (@Catharsis) January 14, 2012
The code and coding sensibilities were remarkably dated. For example, the wonky tab around the current center nav item was using sliding doors, combined with corner images. Pipes inserted with markup or borders. Deep, deep classitis with redundant IDs for good measure. Random markup choices. Yuck.
Anyway, this user style was created to scratch a personal itch, but hopefully you’ll find it just as useful. If you have any questions/suggestions, feel free to get in touch with me on Twitter and let me know.
Download: [User Style] Bing - Clean, Minimal (userstyles.org)
Refactoring Digg.com's Stylesheets using Sass
/via strake
A nice writeup by Chris Eppstein showing an iterative process for converting Digg’s CSS to Sass. Concepts include creating and extending base classes, nesting selectors, and extracting mixins.
CSS: Specificity Wars by Andy Clarke
Specificity is one of the most difficult areas of CSS to grasp. In case the Star Wars analogies are a little too high-level, here’s a key:
- 1000 - inline styles (
<div style="">) - 100 - IDs (
#this) - 10 - classes (
.this), pseudo-classes (:hover), attributes (div[href=]) - 1 - elements (
div), pseudo-elements (:after)
If you always remember that inline styles trump all selectors, you can abbreviate the hierarchy as ICE (IDs, Classes, Elements). Ice — you know, like Hoth. And Tauntauns.
Nailed it.
The Man from Hollywood: a kinetic type experiment in HTML, CSS and Javascript by Tyler Gaw
[The Man from Hollywood] is a Kinetic Type experiment that makes use of Advanced CSS selectors and Webkit CSS properties*. The idea is based off of kinetic type videos that are usually created using After Effects, Flash, or other animation tools. Javascript is used, but minimally, really just to turn class names on and off. All of the animations are accomplished using CSS.
/via @KuraFire
iPad Orientation CSS (Revised)
It doesn’t take much foresight to anticipate that with the rise of Natural User Interfaces (NUIs) like the iPhone and iPad, UI designers will have a greater responsibility to optimize for orientation-based contexts. As such, it’s quite prescient that today, the folks at Cloud Four demonstrated how to serve up stylesheets based on device orientation.
Since I have a feeling I’ll be using this quite a bit in the future, I wanted to build on Cloud Four’s work and find a way to alleviate the following issues:
- Extra HTTP requests
- Not iPad-specific
- Lack of reusability
So, without further ado, here’s my proposed revision to the iPad orientation CSS:
<!-- css -->
@media only screen and (max-device-width: 1024px) and (orientation:portrait) {
.landscape { display: none; }
}
@media only screen and (max-device-width: 1024px) and (orientation:landscape) {
.portrait { display: none; }
}
<!-- example markup -->
<h1 class="portrait">Your device orientation is "portrait"<h1>
<h1 class="landscape">Your device orientation is "landscape"<h1>
As you can see, I’ve also changed the markup in a predictable way. An explanation of the changes and the reasoning behind them can be found below.
1. Extra HTTP requests
Depending on how much work you put into crafting and taking advantage of orientation-based display, you could have entirely different layouts contained in landscape.css and portrait.css. Since extra HTTP requests can bog down page-load time, it would be better performing to embed the media queries into a single stylesheet, if not your main stylesheet as follows:
@media (orientation:portrait) { }
@media (orientation:landscape) { }
The orientation-specific code could then be inserted in between the curly braces. Note that I’ve also removed the “all and” at the beginning of the media query — this is acceptable shorthand per the W3C spec. For more information on CSS3 media queries, please reference the W3C Candidate Recommendation.
2. Not iPad-specific
This CSS targets devices based on their orientation, or (as the W3C explains) based on whether the height of the device is greater or less than the width of the device. What if you only want to target the iPhone and/or iPad and not browsers though? I’m not advocating making Apple devices the new Internet Explorers, but there’s some value in having greater control of your presentation, should you need it.
I posted recently on how to serve up iPad-specific CSS using media queries. To do so, you would change your media queries to target only devices with the “screen” media type that have the maximum device width of the iPad:
@media only screen and (max-device-width: 1024px) and (orientation:portrait) { }@media only screen and (max-device-width: 1024px) and (orientation:landscape) { }
By extension, if you wanted to serve up iPhone and iPad-specific CSS, you would change your media queries to the following:
@media only screen and (max-device-width: 1024px) and (orientation:portrait), only screen and (max-device-width: 480px) and (orientation:portrait) { }@media only screen and (max-device-width: 1024px) and (orientation:landscape), only screen and (max-device-width: 480px) and (orientation:landscape) { }
3. Lack of reusability
Using classes instead of ID’s to denote orientation-based styles would make it a little easier to manage the logic.
<h1 class="portrait">You're Viewing in Portrait Mode<h1>
<h1 class="landscape">You're Viewing in Landscape Mode<h1>
I’m sure Cloud Four didn’t intend to establish ID’s as a convention for this functionality in their example, but I think considering reusability here is important. How can we make sure the “portrait”/”landscape” semantics are all that’s required to potentially display completely different layouts? Just apply the appropriate classes to whichever elements you want to target with a specific orientation.
Having to duplicate code is cringe-worthy, but understandably necessary if we need to replace content and don’t want to use Javascript. What if, however, instead of replacing content, we want to repurpose the existing content? For example, we might want to change the width of an element based on orientation without replacing it wholesale. In this situation, I don’t believe using classes to abstract the logic is appropriate; all of the styling should be directly targeting the elements from the orientation conditional CSS:
<!-- css -->
#content { width: 960px; }
@media only screen and (max-device-width: 1024px) and (orientation:portrait) {
#content { width: 720px; }
}
<!-- markup -->
<div id="content"></div>
Conclusion
The mechanics of optimizing presentation should be fairly invisible to the user. If possible, we should be able to do nothing but tweak static parts of fluid layouts to better accommodate different device widths; however, that doesn’t mean we should overlook opportunities to better optimize content for the user. And while the iPad might not be the spawn of unicorn and wizard, it’s certainly different.
It’s a mobile device that has the potential to be used as often and in as many contexts as a smartphone, but introduces a whole host of additional accessibility scenarios to worry about.
It has a screen size we’re accustomed to designing for, but that’s not an excuse to stop supporting non-iPhone mobile users.
It supports web standards.
Its interface presents us with novel ways of delighting users, but might lead us to fail less-privileged users whom we’re not as interested in designing for.
More than ever, we are accountable to our users as vanguards of usability, accessibility and progressive enhancement. So let’s keep moving forward, and let’s keep providing best-in-class interfaces for everyone, everywhere.
IE User Agent Stylesheets
A must-bookmark resource for all front-end developers. This site displays (and offers for download) quite a few default browser stylesheets, even going so far as to chart the functional stylesheet differences between IE versions 6-9.
If you plan on performing a non-global CSS reset ala Eric Meyer (or with Richard Clark’s HTML5 version), reading this should be considered due-diligence. After all, as a responsible, professional front-end developer, you should know why every line of code in your CSS exists.
From the author:
The UA Style Sheet is a simple set of css styles that each web browser uses before any other css styles are applied.
This chart lists and compares the different default style sheets used to render HTML in the four major versions of Internet Explorer; IE6, IE7, IE8, and IE9 Platform Preview.




![CSS: Specificity Wars by Andy Clarke
Specificity is one of the most difficult areas of CSS to grasp. In case the Star Wars analogies are a little too high-level, here’s a key:
1000 - inline styles (<div style="">)
100 - IDs (#this)
10 - classes (.this), pseudo-classes (:hover), attributes (div[href=])
1 - elements (div), pseudo-elements (:after)
If you always remember that inline styles trump all selectors, you can abbreviate the hierarchy as ICE (IDs, Classes, Elements). Ice — you know, like Hoth. And Tauntauns.
Nailed it.
/via dbsw & cuterobot](http://25.media.tumblr.com/tumblr_l0qilnTihK1qaadrbo1_400.jpg)
