Treehouse: Grow your CSS skills. Land your dream job.

Article Archives

19 comments

Links

Got a couple of slightly-oldie-but-goodies for you:

  • A jQuery plugin by Manos Malihutsakis which allows you do to create custom scrollbars for content areas that do some neat things like move their position and size, style them differently, and use easing.
  • Benjamin De Cock's CSS Playground has a number of stripped down and clever CSS ideas like a slideshow, spinner graphic without images, and some neat navigation ideas.
  • Caleb Ogden uses some CSS3 to make a submit button look like
50 comments

Why use Classes or IDs on the HTML element?

Reader Nicolas writes in:

I'm frequently seeing ID and class specifications to <body></body> and <html></html> elements. I'm curious as to why one would do this? If it is unique to either element, then why not specify body or html in the CSS?…

37 comments

The MoveUp Menu

I got an email quite a while back from Dirk Tucholski who showed me a site called FLOWmarket. He was wondering about how the menu system worked. I thought it looked neat and so set out to build it how I would do it. The idea is that there is a long vertical menu of links, not all of which are visible. As you scroll your mouse up and down the visible area, the menu scrolls itself to reveal …

72 comments

Thank You (2010 Edition)

It's been a tradition for years now around here for me to do a year-end wrap-up. It's a great way of reflecting on the year, sharing some random interesting statistics, and most importantly, saying thank you to everyone who comes to this site. …

68 comments

Poll Results: HTML5 on New Projects

Several folks pointed out that this last poll question was worded a bit strangely:

Would you start a new web project today and not use HTML5?

I worded it that way to elicit comments on why a person or organization would not opt to use HTML. However, that meant you needed to answer Yes if you would not use HTML5 and No if you would, so, possibly a bit confusing, but whattagonnado? The results show that the majority of people …

Body Borders without Markup

Harry Roberts  with a nice technique on using pseudo elements to create the body border effect without extraneous markup (same idea with extra markup gets you older browser support). Read the comments for some other good suggestions. …

44 comments

Load More Sidebar Content When There Is Room

One classic layout conundrum is how much stuff to put in a sidebar. Ideally the height of the main content area and the sidebar are about the same, to avoid either area having a large blank area which can be strange looking and a waste of good web real estate. Go light on sidebar content and short content pages may be just about right but long content pages have a lot of unused sidebar space. Go heavy on sidebar content …

41 comments

WebKit Image Wipes

It's not "spec," but WebKit browsers support image masks. If you are familiar with Photoshop, they work like that. You declare an image to use as as mask. The black parts of that image hide what it is over, white parts of that image show what is underneath, gray is partially transparent. So if you had this image…

The Hacktastic Zoom Fix

Nicole Sullivan on forcing elements to create new formatting contexts with display: table-cell and a string of X's as pseudo content to force it full width. …

The lean, mean, CSS-reset machine.

There are all kinds of CSS resets, from the ever-popular Meyer reset, to the newfangled HTML5 reset. Do you know what the difference between the different ones are? It's a bit hard to picture, even when looking at and comparing the code. Jeff Starr created this new little clever website which allows you to see different types of content with different resets applied, and even pull in your own websites content to try. …

80 comments

Using CSS without HTML

Big thanks to Mathias Bynens for the guest post today! I'd call this a bonafide CSS trick!

A few days ago, Chris tweeted:

If we could stack pseudo elements (e.g. :after:after) we could build a whole website with no HTML other than <html>. Probably good we can’t.

In response to this, I created this quick demo (view in Firefox or Opera), illustrating that technically you don’t need any HTML at all to use CSS.

Since this …

28 comments

The Kick Awesome Show

Nate Croft and Jon Longnecker (remember Jon?) from FortySeven Media have a new video podcast they are producing called The Kick Awesome Show. CSS-Tricks was happy to sponsor Episode 13.

These guys sure look like they have a lot of fun making this show. They do a little Q&A, highlight cool web-things, do music picks (ala their other pet project), etc. It's also super high quality video. Check out the cool ad they did for …

CSS Transition Timing

Nice little article with visual demos on the different timing functions for CSS transitions. The progress bar is neat. Also notice the scaling transform on the table of contents. Not sure I love that exact implementation but I like the concept. …

The Fifth Position Value

Peter-Paul Koch:

If mobile browsers were to implement position: fixed exactly as the desktop browsers do, many sites with fixed elements would become unusable on mobile.

... I believe it’s time for position: device-fixed.…

36 comments

Text Fade Out / Read More Link

A section of text that fades into the nothingness. But wait, a beacon. A "read more" link shines through the darkness. Click upon it and all text is revealed! CSS3 gradients are used for the text fading and jQuery is used to handle the animated reveal.
36 comments

Three-Sided Border

There are many ways to skin a cat. Also, there are many ways to accomplish the same thing in CSS. The three sided border is one of those things, so we'll look at four different examples that all do it. I would think this kind of thing is a bit confusing as a beginner, so hopefully seeing these different bits of code isolated will make it clearer.
39 comments

Poll Results: Does Your Degree Relate To Your Job?

There is a bit of an idea in our little web design world that "nobody who works on the web went to school for it." At least, I get that feeling. Especially from little stories like these:

I have a BS in Botany, but after designing my first website on the university servers, I was hooked. Did a couple of sites for friends while working in a plant lab, and now I’m a full time web programmer and designer.…

You Must Learn JavaScript

It's really unavoidable these days, and that's good because it's awesome. Here are some choice quotes from Kenny Meyers:

Not every company is a Ruby shop. Not every company is a .NET shop. It’s my belief that 99% of the time both of these companies will need someone who knows JavaScript, and knows it well.

When people talk about HTML5, they are talking mostly about JavaScript.

And regarding frameworks and Chicken/Eggery:

CodeIgniter certainly helped me understand PHP better. jQuery gave …

CSS3 Walking Man

The illustrated backgrounds that slide by with faded edges are the best part.…

276 comments

Design v8

I had some extra time over Thanksgiving so I decided to spend it doing some recreational designing of this site. Here's a few quick notes (I need to get back to content!):…

Formatting CSS3

With all the vendor prefixes and all the new complex properties like animations and gradients, it's nice to format them so they are nicely readable. I agree with David DeSandro here that lining up the values makes for nice lookin' CSS. It would be cool if one of the "CSS prettifier" services could incorporate this.…

24 Ways 2010

Twenty four great blog posts by top industry peeps in twenty four days. This year it's going print as well.…

ImageOptim

Maybe you've heard of things like Pngcrush before which supposedly does an amazing job at optimizing png files, but then when you go check it out it turns out it's this nerdy command line tool with crappy documentation and it just doesn't look like it's worth the hassle. Enter ImageOptim, which is a Mac app with a super simple user interface for using Pngcrush as well as a bunch of other similar awesome compression tools. Literally just drag and drop …

56 comments

Keep Margins Out of Link Lists

When building a menu or other list of links, it's generally a good practice to use display: block; or display: inline-block; so that you can increase the size of the link target. The simple truth: bigger link targets are easier for people to click and lead to better user experience.…

25 comments

Google CDN Naming Conventions (and You)

You've seen this before:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>

This is a way you can load a JavaScript library like jQuery directly from Google's CDN (Content Delivery Network). You can get quick copy/paste access to these from ScriptSrc.net.

See in that above URL how it is pointing to 1.4.4 specifically? That little part of the URL can be tweaked. Perhaps you've seen it used that way before.

/1.4.4/ Loads this very specific version of jQuery which will never change.
/1.4/ Today,

Photoshop-Like CSS3 Gradient Generator

If you are a designer who is used to creating gradients with Adobe Creative Suite products, you'll likely enjoy this. It's the same interface with the little color pointers that you slide around, click to add, drag to remove, and double-click to edit the color. This makes it way easier to create gradients that are more complex than a fade from one color to another. I do wish it used the more solid property list / syntax re: CSS3Please though.…

224 comments

Perfect Full Page Background Image

Four techniques are explored on accomplishing a full page background image that conforms to our exceptions: no white space, scales as needed, retains aspect ratio, centered, and more.
23 comments

What is Cross Site Scripting or XSS?

I think the name "cross site" is confusing. It's easy to hear that and think it involves code on one website attacking code on another website. That's not what it is. Not to mention its unfortunate "true" acronym.

It simply means: executing abritrary JavaScript code on the page.

20 Things I Learned about Browsers and the Web

Really neat presentation of a book by the Google Chrome Team. Everyone seems to be calling it an "HTML5" book There is certainly a bunch of HTML5 going on, but there is also loads of CSS3 and clever JavaScript at work. Read a few pages then close the tab and then go back to it to check out a fun bookmarking idea.

Of particular interest is how they are using window.history.pushState() and window.history.replaceState() to change the URL in the browser …

20 comments

My Slides from the jQuery Summit

At this year's jQuery Summit I gave a mostly-totally-revised version of my talk "Solving Common Client Requests with jQuery" that I originally gave at the Bay Area jQuery Conference earlier this year.

I always think slides are a little weird outside of the context of the talk, but I also know some folks like to see them. These also happen to contain some JS Bin URL's which might be of some use.…

32 comments

Hash Tag Links That Don’t Headbutt The Browser Window

Using hash-tag links with a fixed position header can be problematic, as the element may be hidden underneath the header as the browser will scroll until the element headbutts the top of browser viewport. There are a couple of ways we can fix this...
39 comments

Show Image Under Text (with Acceptable Fallback)

Updated April 2014 with more modern information.

WebKit supports the cool background-clip CSS3 property, which you can use to do some pretty neat stuff. The first time we touched on it was the iPhone Slide-to-unlock idea where we set a gradient to animate through the background of the text. Then we touched on it again for the transparent borders idea.

Let's take a look at using it to have an image be visibile only through the letters of the text. …

45 comments

Exploring Markup for Breadcrumbs

What is the most appropriate possible markup for breadcrumbs? We'll take a look at a bunch of different possibilities of various complexities and semantic success. Then also see what Google has to recommend as well as what HTML5 has in store for them.

New Screencast: CSS3 Slideup Boxes

Follow along as we use a few very simple CSS3 transitions to create a "slideup" box effect. Roll over the box with your mouse, and the title of the box slides out of the way and a more descriptive stylized box of information jockeys its way into place. This is supported in modern version of Gecko, WebKit, and Opera browsers. No Internet Explorer support yet, but no fallback is needed, the link works and the information shows as expected.


View

CSS3 Finalize

jQuery plugin from Han Lin Yap which allows you to write CSS3 without vendor prefixes. This plugin will read through your CSS files and in-document <style> blocks, find the CSS3 stuff, then append a new <style> block to your page with the appropriate vendor extensions for the browser you are in.

This solves one of the most common complaints about using CSS3, that is bloats your stylesheet with loads of repetitive properties.

Worked great in my limited testing. I …

CSS Gradients for IE9

This article by Robert Biggs goes into a solution for using SVG for gradients in Internet Explorer 9, because it doesn't support CSS3 gradients. The core benefit being that the SVG image format is XML and actually rather similar in structure to how you create a -webkit-gradient. Thus you get the benefit of programatic declaration of colors and ease of updating.

Earlier in the article, Biggs also makes a good point about transitions and why doing them through CSS …

69 comments

Breadcrumb Navigation with CSS Triangles

Did you know you can make triangles with pure CSS? It's pretty easy. You just make a block level element with zero width and height, a colored border on one side, and transparent borders on the two adjacent sides. They are fun for all kinds of things, like little arrow sticking out from speech bubbles, navigation pointers, and more. Often times these are just visual flourishes, undeserving of dedicated markup. Fortunately, pseduo elements are often a perfect fit. That is, …

41 comments

Happy Halloween

HTML, CSS, and JavaScript got invited to a halloween party. They decided they would all dress up as each other!

HTML went as JavaScript:

<div id="pumpkin" onclick="alert('Boo!');"></div>

JavaScript went as CSS:

var jackolantern = document.getElementById('pumpkin'); jackolantern.style.color = "orange"; jackolantern.style.backgroundColor = "black";

CSS went as HTML:

#pumpkin:before { content: "Happy Halloween!"; }

Happy Halloween everyone!…

Rotating Molecules with 3D Transforms

Click-and-drag to rotate these complex objects through a pseudo three dimensional space. It's a familiar design pattern, but one that is particularly difficult to pull off. No Flash, not even canvas. Just some fancy JavaScript and CSS (WebKit 3D Transforms). And it works on Mobile Safari with touch events as well!…

48 comments

So You Need To Fill a Dropdown Dynamically

You have one dropdown menu, and depending on the user's choice in that one, a second dropdown gets filled with choices. Let's cover three different ways you can go about that.…

52 comments

Commas Before

Marc Grabanski brought up and interesting idea on Twitter yesterday.

Commas before or after the line on json objects and multi var definitions?…

109 comments

Garage Door Style Menu

Originally published on July 21, 2008 as only a jQuery technique. Now updated to include CSS3 and a combo technique which is mo' betta.

A garage door style menu is where an image (the "door") slides up to reveal something behind it. We'll do this in two ways, with CSS3, and with jQuery. Then we'll combine them into a progressive enhancement way to handle it. …

72 comments

Parent Selectors in CSS

Let's be clear here, just in case someone is finding this from a search engine: there are no parent selectors in CSS, not even in CSS3. It is an interesting topic to talk about though, and some fresh talk has surfaced.

Back in 2008, Shaun Inman suggested the syntax:

a < img { border: none; }

[Corrected the following sentence]: In this example, it would select a tags but only if they contained an img tag. (Aside: this would …

Formalize CSS

Framework by Nathan Smith for nice looking, HTML5 ready, progressively enhanced, cross-browser forms.…