Digital UK Design Blog

10 CSS shorthand techniques you’ll use everyday

By frog on September 28th, 2008 at 13:20 BST | 53 Comments »

10 CSS shorthand techniques you'll use everyday

CSS shortland is a technique of writing mulitple declarations and values in a single line of CSS code. The advantages of using shorthand is to primarily reduce the CSS file size, but there are other benefits. A bloated and disorganised stylesheet can be hard to debug if you encounter problems, especially if you wrote it and another unfortunate colleage has to fix it while your away sunning it in some hot climate.

To make it easy we’ll look at the most commonly used CSS declarations, write them in longhand, then sprinkle our magic, resulting in a neat, short line of code.

There are many permutations you can use with each declaration and using them all in an example would be a headache, so we’ll pick one, then simplify that, hopefully giving you a flavor of CSS shorthand.

0 values

The golden rule is if the value is 0 you don’t have to specify the unit (px/em/%). You may write:

01|  padding: 10px 5px 0px 0px;

try

01|  padding: 10px 5px 0 0;

Remove Selectors

A selector is basically the element you’re applying the styling to, for instance h1, h2, h2, div, strong, pre, ul, ol etc.. If your using a class (.classname) or an ID (#idname) you don’t need to include the selector within your declaration.

01|  div#logowrap

let’s lose the selector from within this CSS declaration

01|  #logowrap

So the selector in this case was div

* is the joker in the pack

Use * wisely in CSS as it’s a firey little monkey. * is a wildcard declaration, you can use it to set a group of declarations to all or parts of your design, for example:

01|  * {
02|  margin: 0;
03|  }

This declaration would set the margin to zero on every element on your page. Alternatively, set this wildcard with an element, such as:

01|  #menu * {
02|  margin: 0;
03|  }

This declaration would set the margin to zero on every element within #menu.

Backgrounds

Background properties include the ability to set a colour, an image, image position and image repetition. You could write:

01|  background-image: url("logo.png");
02|  background-position: top center;
03|  background-repeat: no-repeat;

Becomes

01|  background: url(logo.png) no-repeat top center;

Colours

The most common way of specifying a colour in CSS is to use hexadecimal notation: a (#) followed by six digits. One great shortcut that many don’t know about is that when a colour consists of three pairs of hexadecimal digits, you can omit one digit from each pair:

#000000 becomes #000, #336699 becomes #369

This technique only works if you have three pairs, here are some examples where you can’t omit any values:

#010101, #223345, #FFF000

Margin

Apply margin to all four sides of an element like this:

01|  margin-top:0px;
02|  margin-right:10px;
03|  margin-bottom:0px;
04|  margin-left:10px;

Let’s simplify this even more by removing zero value prefixes and merging it into one declaration:

01|  margin:0 10px 0 10px;

When applying padding, margin and border (and possibly a few others) you set these four values in a clockwise direction. Compare this to the hours on a clock, start with 12, 3, 6, 9, all in a clockwise direction. With this in mind there is another trick to slim this declaration down. Look out for two pairs, if the top and bottom match, and the left and right match then your a winner! Omit the 3rd and 4th values. The first value represents the top and bottom value, the second represents the left and right.

So let’s simplify this declaration down again with the pairing technique that’s just been explained:

01|  margin:0 10px;

The result is the element would attain margin of 10px to the left and right sides, and zero to the top and bottom. Here are a few declarations where the pairing technique can’t be applied:

Padding

Same principles in padding as explained in margin above.

01|  padding-top:0px;
02|  padding-right:10px;
03|  padding-bottom:0px;
04|  padding-left:10px;

Becomes

01|  padding: 0 10px;

Borders

Borders are a bit more complicated since they can also have a style and a colour. To give an element a one pixel solid black border on all sides, you could write:

01| border-width:1px;
02| border-style:solid;
03| border-color:#000;

Becomes

01| border:1px solid #000;

I typically write in order of width style color.

We can also set different widths on all four sides of the box element by writing:

01| border-top-width:1px;
02| border-right-width:2px;
03| border-bottom-width:3px;
04| border-left-width:4px;

The CSS shorthand for this would be:

01| border-width:1px 2px 3px 4px;

Finally we could style just the left and right like this

01| border-right:1px solid #000;
02| border-bottom:1px solid #000;

This would be

01| border:1px solid #000;
02| border-width:0 1px 1px 0;

Set a default style for all four sides then overwrite the widths below.

Fonts

There are many properties for font, just like the background properties. In a complex string you may write:

01| font-style:italic;
02| font-variant:small-caps;
03| font-weight:bold;
04| font-size:1em;
05| line-height:150%;
06| font-family:Verdana, Arial, sans-serif;

You could write

01| font:italic small-caps bold 1em/150% Verdana, Arial, sans-serif;

Lists

01| list-style-type:square;
02| list-style-position:inside;
03| list-style-image:url(filename.gif);

And finally

01| list-style:square inside url(filename.gif);

Credit to 456bereastreet for the inspiration to write this useful 10 shorthand CSS tips.

If you want to download a quick reference guide in PDF you can by clicking this link.

Dyson do hoovers right? Yeah but guess what, now they do hand dryers… AWESOME hand dryers too.

I recently completed a training course for work on First Aid training at HACs in Harrogate and stumbled across an interesting machine attached to the wall. After reading the instructions it turned out to be a new hand dryer from Dyson. The instructions said to slowly lower hands into the machine, then slowly pull them out, so I did.

OMG! OMG! That was amazing!

Within 10 seconds and my hands were completely dry, not a drip or damp patch in sight. Great, whatever, this machine is amazing. You have to find one and try it.

The design

The Dyson Airblade™ hand dryer works in just 10 seconds – scraping water from hands like a windscreen wiper. It’s the fastest hand dryer, powered by the unique Dyson digital motor. A HEPA filter purifies the air before blowing it onto hands, so it’s also hygienic. And it uses up to 80% less energy than warm air hand dryers.

The problem with other hand dryers

Dyson is about developing new technology to solve everyday problems, such as hand dryers that are too slow and can take as long as 44 seconds to dry hands. It’s because of their motors. They can’t create enough airflow to remove water from hands effectively.
They’re also unhygienic since they can’t filter the bacteria from the air.

Read more on the Dyson Airblade website

First look at the UK’s new ID cards

By frog on September 25th, 2008 at 17:11 BST | 2 Comments »

Not surprisingly these designs follow in the same suit as the UK passport and driving license designs.

Example front

Example back

Quick facts

  1. Each card will carry a picture and a chip holding the person’s name and date of birth, fingerprint records and other biometric data.
  2. It will also detail the holder’s visa status and right to work.
  3. The cards will be issued to foreign nationals from November and from next year to people working in airports and other high security jobs.
  4. From 2011 everyone over the age of 16 applying for a passport will have their details added to a national identity register.

Let us know your thoughts.

Home Secretary Jacqui Smith has revealed the design for the new identity card will be unveiled today. Each card will carry a picture and a chip holding the person’s name and date of birth, fingerprint record and other biometric data.

When will they be introduced?

From November the cards will be issued to foreign nationals and from next year to people working in airports and other high security jobs.

From 2011 everyone over the age of 16 applying for a passport will have their details added to a national identity register.

ID cards are bad news right?

After a string of government data loss blunders there are fears about the security of personal data, with opponents saying that ID cards are unnecessary, costly and impinge liberty.

Ministers argue the cards will boost national security, tackle identity fraud, prevent illegal working and improve border controls.

Liberty Director Shami Chakrabarti said:

“This week the Prime Minister said he doesn’t do PR but clearly the Home Secretary wasn’t listening.

“The public will yawn at yet another re-launch of this scheme and if the card came with loyalty points, we still wouldn’t buy it.

“Picking on foreigners first is divisive politics; as costly to our race relations as our purses.”

Earlier this week Home Office minister Meg Hillier was forced to row back after claiming ID cards could be issued to children as young as 14.

Credit ITV news, all rights reserved

Shopping online - returns policies

By squid on September 24th, 2008 at 21:11 BST | 9 Comments »

I ordered my Garmin Forerunner 405 from work today.

Having shopped around endlessly for the last few weeks I narrowed it down to a toss up between Amazon and the possibility of cashback; or, as luck would have it, Ebuyer where I could get free staff delivery.

Then, at the last minute an alternative site cropped up where I could get the unit £5 cheaper including free delivery. Ho hum - tempting.

I very nearly just got it there and then, but then decided to check the returns policy.

The company in question is Pegasus Fitness. They look bona fide - they have what appears to be a proper postal address, standard telephone number etc so I have no qualms there. However if you put the distance selling regulations aside and look at what happens for faults during the warranty period Pegasus have theirs very locked down:

What If An Item Fails After Being Used?

Inform us by email at support@pegasusfitness.co.uk exactly what has failed and return the item to Pegasus Fitness by post. The original manufacturer will be informed and the item will be inspected by them to verify the stated fault. Only then can a refund be issued. We will offer to refund or replace your purchase.

We will only accept items that have failed up to fourteen days after delivery.

Plus:

In ALL CASES, the customers is responsible for the costs of returning items to Pegasus Fitness.

Let’s compare this to Ebuyer’s returns policy:

Items Faulty on Arrival

If your items are faulty on arrival, you have 28 calendar days in which to inform us of the fault (please note that for our business customers, this is 14 calendar days). Items should be returned in their original packaging complete with all accessories and documentation. Once we have verified the fault, we’ll issue a replacement or full refund to you via your original payment method and reimburse your reasonable return carriage costs. We test returned items, and if a returned item is found not to be faulty by our technicians we will return the item to you, in this instance you will be liable for the return carriage.

And further:

Items Faulty in Warranty Period

If any of your purchases develop a fault, and it’s more than 28 calendar days since receipt, then provided your item is within its warranty period, you are entitled to a warranty repair. In some cases, manufacturers provide a specialist full on-site service and/or telephone help facilities for your convenience which we recommend you use in order to correct the fault quickly.

Notice the very subtle but very important differences. If I order the 405 from Ebuyer then I get:

  1. Longer to identify a fault on arrival - an extra 14 days in fact.
  2. The return shipping paid for if within 28 days.
  3. Encouraged to return my item to the manufacturer if under warranty - but I don’t read any compunction to do so, it sounds like I can still deal with Ebuyer if I wish.

These extras make that £5 extra well spent at Ebuyer me thinks, though I’m a bit biased as they’re my boss. Pegasus are doing a fantastic job of beating Ebuyer on that price, a really impressive feat in fact when Ebuyer are already cheaper than Amazon!

Conclusion: shop around on the Internet but always make sure you read the small print before you grab yourself a bargain.

 Page 1 of 7  1  2  3  4  5 » ...  Last » 

©2006 - 2009 The Floating Frog