Digital UK Design Blog

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

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

September 24, 2008 | News & Reviews | Stephen O'Neill | 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.

If you visit Google today you should notice a link under the search bar:

U.K. kids design a Google logo. Vote for your favourite.

At Google, we like to reflect the ever changing world of our users through the logo designs on our homepage. The ‘Doodle 4 Google’ competition asks young people across the UK to design their own ‘Google Doodle’ and the winning entry will be used on the Google homepage in the UK on 1st October.

For this year’s contest, which has been held in association with the Daily Mirror’s ‘Pride of Britain’ awards, 70k doodles were created across the UK. Our judging panel have selected their top 48, and you can vote for your favourite below.

The voting system is split into the follow age groups, 5-7 yrs, 7-11 yrs, 11-14 yrs, 14-16 yrs.

Who I’d vote for:

Age group 5-7 yrs

My friendly community
My community has friendly people to help out and places to play.

Name: Amelia Warcup
Age: 6

I love this, it’s simple and bright.

Age group 7-11 yrs

Helping Together
My doodle shows lots of people working together to help repair the Google sign. If everyone worked together as a team, they could repair the earth’s environment. I hope this message is spread around the world, so that people start helping to make the world a better place

Name: Anna Readman
Age: 11

In my opinion this age group created the best logos by far. It was extremely hard to choose a favourite as I genuinely loved 4-5 of them. It’s amazing what children can create at such a young age.

Age group 11-14 yrs

I love my community
I choose Graffiti because Bristols background are highly influenced by artists such as Banksy, therefore it is normal for Bristol’s community to be enriched with graffiti. The two hands represent our community where black and white people can unite and help each other to develop the place where we live in. Unfortunatly, there is alot of rubbish in my community and I hope to make a point and do my part to help the community.

Name: Thang Huynh
Age: 14

Brilliant creative imagination by Thang aged 14

Age group 14-16 yrs

Happy Times
When trying to fit my doodle in to theme of ‘My Community’ I used different pictures that normally feature in a community. For example, people close together on the letters, love hearts to symbolise relationships and colour to add more of an effect. The people are all different races but still are playing together in harmony. The rainbow symbolises peace and the joining of different communities.

Name: Daniel Thorne
Age: 15

Just love this, it’s awesome.

Have a look yourself and see if your winners match mine, View all entries and vote here

First day of autumn 2008

September 22, 2008 | News & Reviews, Photography | Gary Hartley | 2 Comments »

Fall Equinox – day when night and day are of equal length.

Today is the first day of autumn and as a budding photographer I’m very exciting about the thought of the array to photographs I’ll be able to take in my first season in photography, notably the changing colours of the leaves on the trees, turning into deep reds and yellows.

Credit: Ming chai, Flickr.

Hopefully I’ll be able to produce some memorable moments.

I had an issue today when installing pytrainer. It wanted to install some extra python packages but it couldn’t.

The reason was that I had python2.5 v2.5.2-2ubuntu5 installed but the extra packages depended on an older version – 2.5.2-2ubuntu4.1.

I don’t know how I had ended up such a knot, but the ubuntu5 packages I had seemed like they had been obsoleted from hardy-proposed which is clearly one of my sources lists. Ho hum.

Downgrading through the GUI wasn’t intuitive, I tried to ‘force version’ but that seemed to have no effect.

The answer lies in the command line, and is explained by this forum post.

Aptitude lets you specify a version parameter over the command line, so I used sudo aptitude install python2.5=2.5.2-2ubuntu4.1 to install the older version. This then resolved what other packages needed downgrading, gave me a summary, and did the business.

I run Windows Vista on dual boot. My inclination is to get rid of it altogether, but I paid for a license thanks to the Microsoft Tax when I bought the machine and sometimes vendors (Garmin for example) only support Windows.

I gave Windows Vista 12GB with virtually no applications and it’s used it all up. It refuses to install Vista SP1 because there isn’t enough room.

Rubbish.

Enter GParted – the Gnome Partition Editor. It is included with the Ubuntu install CD which doubles as a live CD (just select the ‘try Ubuntu without changing my system’ option when you boot the CD). Boot from the CD, run GParted, drag your partitions around and let it do its thing. A few hours of disk crunching later you have successfully resized your ext3 and NTFS partitions.

Impressive stuff this free and open source software.

Incidentally, I should say that I’m a bit grumpy that Vista needs more than 12GB just to exist and with virtually no software installed. That really sucks.

Something bizarre happened today on the beach at Scarborough’s North Bay. Viewing from afar on the cliff top I noticed a crowd gathered, but being too far away to see clearly, I took out my Canon 40d and zoomed in, and too my amazement I could see a car a good 30 feet out in the sea. A bizarre accident caused by a careless driver or a stunt gone wrong? Wasn’t sure, so I went, with my trusty camera, to find out.

Car in sea

You can see people frantically trying to push it back onto the beach.

With help from a Land Rover the vehicle is hauled onto dry land.

A job well done.

I hope these guys were insured, if not they better get drying those seats as it’s going to be a damp drive home.

Page 1 of 3123

©2006 - 2009 The Floating Frog