Tag Archives: Tips

CSS Bug: box-sizing and min-height

, , ,

One thing I’ve (fairly) recently discovered (courtesy of Paul Irish) is the use of box-sizing in CSS3. This little nugget of CSS joy allows you to set element dimensions regardless of padding and borders. In some situations, this is invaluable. For example: say you want to have a container that’s 100% wide but has padding of 20px around the edges. Without knowing what the size of the screen is, you can only do this via javascript or by creating a wrapping container, both of which are annoying. With box-sizing, you can set the padding to whatever you want and it’ll still size perfectly to 100%. Wonderful! Isn’t it?

Read More »

Truthy/Falsy

, , ,

In javascript (and some other languages for that matter) non-boolean values can behave as booleans under certain circumstances. This is often referred to as “truthy” or “falsy,” that is, it’s like a boolean true or false, but technically isn’t exactly the same, so it’s “kind of true” and “kind of false.” What am I talking about?

Read More »

JS Optimisation #3 – If Statement

, ,

This tip points out a shorthand way of implementing a simple if statement.

Sometimes all you want is a simple “if this, then do that” one-liner statement, but you end up using three lines of code when really it can be a lot more straightforward.

The ternary if else statement is a great shorthand for writing a simple if else on one line without it confusing other developers who read your code. But what if you don’t want the else part?

Read More »