Tweet For Code #2

By  on  

You don't need a thousand lines of code to make a big difference in any coding language.  Oftentimes it's quite the opposite:  a few tiny code snippets can do a world of good and accomplish big things.  I asked my Twitter followers to tweet to me their favorite tiny snippets of code -- that's a bit difference to try to pack into 140 characters!  Here are my favorites from this round!

Comma-separated Lists without Server-Side Logic

Want to make a HTML list of items look like a real, comma-separated list?  Check this out:

I implemented this on my upcoming redesign with great effect, and used it on the MDN redesign.

Pure CSS Sliders

The following snippet use max-height to implement CSS-only sliders with overflow hidden:

I wrote about this a while back -- and awesome technique that too few developers know about.

3-Column Grid

Want a nice 3-column grid generator for your SASS projects?

I'm impressed this could fit in a tweet but well done!

JavaScript Var Swap

Ever wanted to swap the contents of two JavaScript vars?  Probably not but hey, it's pretty simple:

Not the most practical but I expected there to be more code involved.

abbr and attr

Hovering over an abbr element usually gives you the full text representation, but what if you're on mobile?  Here's the answer:

You could do this with a number of properties, but this is a nice usage.

*waves*

I had no idea what I'd see when I executed this into the JavaScript console, but I'll let it act as the conclusion to this post:

See you next time!  I can't wait to see what you all come up with next!

Recent Features

  • By
    Facebook Open Graph META Tags

    It's no secret that Facebook has become a major traffic driver for all types of websites.  Nowadays even large corporations steer consumers toward their Facebook pages instead of the corporate websites directly.  And of course there are Facebook "Like" and "Recommend" widgets on every website.  One...

  • By
    CSS vs. JS Animation: Which is Faster?

    How is it possible that JavaScript-based animation has secretly always been as fast — or faster — than CSS transitions? And, how is it possible that Adobe and Google consistently release media-rich mobile sites that rival the performance of native apps? This article serves as a point-by-point...

Incredible Demos

  • By
    Dynamically Load Stylesheets Using MooTools 1.2

    Theming has become a big part of the Web 2.0 revolution. Luckily, so too has a higher regard for semantics and CSS standards. If you build your pages using good XHTML code, changing a CSS file can make your website look completely different.

  • By
    Adding Events to Adding Events in MooTools

    Note: This post has been updated. One of my huge web peeves is when an element has click events attached to it but the element doesn't sport the "pointer" cursor. I mean how the hell is the user supposed to know they can/should click on...

Discussion

  1. MaxArt

    The first one can be achieved for IE8 too with some adjustments:

    ul > li:before { content: ","; }
    ul > li:first-child:before { content: none; }
    
  2. For the first tip, the good old (IE7 compliant) sibling selector is also perfect and requires only one rule:

    li + li {blabla}
    
  3. abhi

    How does this work?

    b = [a, a = b][0];

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!