Top Website Designing: Call:-+91-9582929295(India) or +1-917-310-3767(US)

Blog Archive

Home
Graphic Designing
Tips and Tricks

Any suggestion/comment/feedback/question is welcome. We offer tech support for any website/design related issues so if you are facing any problem, contact us now. We only charge if we resolve the issue.


The flexible box layout module — or “flexbox,” to use its popular nickname — is an interesting part of the W3C Working Draft. The flexbox specification is still a draft and subject to change, so keep your eyes on the W3C, but it is part of a new arsenal of properties that will revolutionize how we lay out pages. At least it will be when cross-browser support catches up.

In the meantime, we can experiment with flexbox and even use it on production websites where fallbacks will still render the page correctly. It may be a little while until we consider it as mainstream as, say, border-radius, but our job is to investigate new technologies and use them where possible. That said, when it comes to something as fundamental as page layout, we need to tread carefully.

The Display Property

So what is flexbox, and why was it created? First, let’s look at how we currently lay out pages and some of the problems with that model.

Until last year, most of us were using tables to lay out our pages. Okay, maybe not last year! But I suspect that many of you reading this have been guilty of relying on tables at some point in your career. At the same time, it actually made a lot of sense. And let’s face it: it worked… to a point. However, we all then faced the reality that tables were semantically dubious and incredibly inflexible. And through the haze of this mark-up hangover, we caught a glimpse of the future: the CSS box model. Hurray!

The CSS box model allowed us to tell the browser how to display a piece of content, and in particular how to display it as a box. We floated left and right, we tried to understand what inline-block meant, and we read countless articles about clearfix, before just copying and pasting the clearfix hack-du-jour into our CSS.

For those of us testing our websites back to IE6, we had to grapple with hasLayout and triggering it with the following or some similar fix:

* html #element {
height: 1%;
}

The box model worked, and in most cases it worked well. But as the Web entered its teenage years, it demanded more complex ways of laying out content and — thanks to a certain Mr. Ethan Marcotte — of responding to the size of the browser and/or device.

Percentage + Padding + Border = Trouble

Here’s another problem with the current box model: absolute values for padding, margin and border all affect the width of a box. Take the following:

#element {
width: 50%;
border 1px solid #000;
padding: 0 5px;
}

This will not give us a box that is 50% of its parent. It will actually render an element that is 50% of the parent’s width plus 12 pixels (2-pixel border + 10-pixel padding). You could set the padding as a percentage value (although not for input elements in Firefox!), but adding percentage values of widths to the pixel values of borders can cause mathematical problems.

There are two ways to fix this problem. The first is to use the new CSS3 box-sizing property, and setting it to border-box:

#element {
box-sizing: border-box;
width: 50%;
border 1px solid #000;
padding: 0 5px;
}

This new CSS3 panacea effectively tells the browser to render the element at the specified width, including the border width and padding.

The second way to fix this problem is to use flexbox.

Many Problems, Many Solutions

The W3C responded with a suite of answers: the flexible box model, columns, templates, positioned floats and the grid. Adobe added regions to the mix, but they are not yet supported by any browser.

The display property already has no less than a staggering 16 values: inline, block, list-item, inline-block, table, inline-table, table-row-group, table-header-group, table-footer-group, table-row, table-column-group, table-column, table-cell, table-caption, none and inherit.

And now we can add a 17th: box.

Living In A Box

Let’s take a look at flexbox, which brings with it a brand new value for the display property (box) and no less than 8 new properties. Here’s how the W3C defines the new module:

In this new box model, the children of a box are laid out either horizontally or vertically, and unused space can be assigned to a particular child or distributed among the children by assignment of flex to the children that should expand. Nesting of these boxes (horizontal inside vertical, or vertical inside horizontal) can be used to build layouts in two dimensions.

Sounds exciting! The Working Draft expands on this a little:

Flexbox… lacks many of the more complex text or document-formatting properties that can be used in block layout, such as “float” and “columns,” but in return it gains more simple and powerful tools for aligning its contents in ways that Web apps and complex Web pages often need.

Now this is beginning to sound interesting. The flexbox model picks up where the box model leaves off, and the W3C reveals its motivation by noting that “Web apps and complex Web pages” need a better layout model. Here’s a list of the new flexbox properties:

  • box-orient,
  • box-pack,
  • box-align,
  • box-flex,
  • box-flex-group,
  • box-ordinal-group,
  • box-direction,
  • box-lines.

For the sake of brevity, I will use only the official spec’s properties and values, but do remember to add the vendor prefixes to your work. (See the section on “Vendor Prefixes and Cross-Browser Support” below.)

You might also want to check out Prefixr from Jeffrey Way, which can help generate some of the CSS for you. However, I found that it incorrectly generated the display: box property, so check all of its code.

Everything Will Change

If you take the time to read or even browse the latest Working Draft (from 22 March 2011), you’ll notice a lot of red ink, and with good reason. This spec has issues and is still changing; we are in unchartered waters.

It’s worth noting that the syntax used in this article, and by all current browsers, is already out of date. The Working Draft has undergone changes to much of the syntax used in the flexbox model. For example:

display: box;

This will become:

display: flexbox;

Other changes include some properties being split (box-flex will become flex-grow and flex-shrink), while others will be combined (box-orient and box-direction will become flex-direction). Indeed, anything that starts box- will be changed to flex-. So, keep your eyes on the spec and on browser implementations. (CanIUse helps, but it doesn’t cover all of the properties.)

PaRappa the Wrapper

Using flexbox often requires an extra div or two, because the parent of any flexbox element needs to have display set to box. Before, you could get away with the following:

<div style="float: left; width: 250px;"> Content here </div>
<div style="float: right; width: 250px;"> Content here </div>

Now with flexbox, you’ll need:

<div style="display: box">
  <div style="width: 250px"> Content here </div>
  <div style="width: 250px"> Content here </div>
</div>

Many of you have already turned away, insulted by this extra mark-up that is purely for presentation. That’s understandable. But here’s the thing: once you master the CSS, this extra containing div becomes a small price to pay. Indeed, you’ll often already have a containing element (not necessarily a div) to add display: box to, so there won’t be a trade-off at all.

On a broader note, sometimes you need presentational mark-up. It’s just the way it goes. I’ve found that, particularly when working on cross-browser support for a page, I have to add presentational mark-up for browsers such as IE6. I’m not saying to contract “div-itis,” but because we all use HTML5 elements in our mark-up, we find that sections often need div containers. That’s fine, as long as it’s kept to a minimum.

With this in mind, let’s get busy with some code. I’ve put together a demo page, and you can download all of the source files.

screenshot

Over the next few paragraphs, we’ll use the new flexbox model to create a basic home page for a blog. You might want to launch a latest-generation browser, though, because we’re now coding at the cutting edge. And it’s an exciting place to be.

box-flex

Let’s start with the basics: box-flex. Without box-flex, very little can be achieved. Simply put, it tells the browser how to resize an element when the element is too big or small for its parent.

Consider the following classic problem. You have a container with three children that you want to position side by side. In other words, you float them left. If the total width of these boxes is wider than that of the parent — perhaps because of padding, margin or a border — then you need to either specify exact widths in pixels (which is not flexible) or work in percentages (and the sometimes mind-bending calculations that come with them!).

Here’s the problem we have on our Fruit Blog, with three 320-pixel-wide asides (plus padding and margin) inside a 920-pixel-wide container:

screenshot

As you can see, the content is wider than the parent. However, if we set set the parent to display: box and each of these asides to box-flex: 1, then the browser takes care of the math and renders the following:

screenshot

So, what exactly has happened here?

The box-flex property refers to how the browser will treat the width of the box — or, more specifically, the unused space (even if that space is negative — i.e. even if the rendered boxes are too big for the container) — after the box has rendered. The value (1 in our example) is the ratio. So, with each aside set to a ratio of 1, each box is scaled in exactly the same way.

In the first instance, each aside was 320 pixels + 20 pixels of padding on the left and right. This gave us a total width of 360 pixels; and for three asides, the width was 1080 pixels. This is 160 pixels wider than the parent container.

Telling the browser that each box is flexible (with box-flex) will make it shrink the width of each box — i.e. it will not change the padding. This calculation is a fairly easy one:

160 pixels ÷ 3 asides = 53.333 pixels to be taken off each aside.

320 pixels − 53.333 = 266.667 pixels

And, if we look in Chrome Developer tools, we will see this is exactly how wide the box now is (rounded up to the nearest decimal):

screenshot

The same would be true if each aside had a width of 100 pixels. The browser would expand each element until it filled the unused space, which again would result in each aside having a width of 266.667 pixels.

This is invaluable for flexible layouts, Because it means that your padding, margin and border values will always be honored; the browser will simply change the width of the elements until they fit the parent. If the parent changes in size, so will the flexible boxes within it.

Of course, you can set box-flex to a different number on each element, thus creating different ratios. Let’s say you have three elements side by side, each 100 pixels wide, with 20 pixels padding, inside a 920-pixel container. It looks something like this:

screenshot

Now, let’s set the box-flex ratios:

.box1 { box-flex: 2; }
.box2 { box-flex: 1; }
.box3 { box-flex: 1; }

Here’s what it looks like:

screenshot

What just happened?!

Well, each aside started off as 140-pixels wide (100 pixels + 40 pixels padding), or 420 pixels in total. This means that 500 pixels were left to fill once we’d made them flexible boxes.

However, rather than split the 500 pixels three ways, we told the browser to assign the first aside with a box-flex of 2. This would grow it by 2 pixels for every 1 pixel that the other two boxes grow, until the parent is full.

Perhaps the best way to think of this is that our ratio is 2:1:1. So, the first element will take up 2/4 of the unused space, while the other two elements will take up 1/4 of the unused space (2/4 + 1/4 + 1/4 = 1).

2/4 of 500 pixels is 250, and 1/4 is 125 pixels. The final widths, therefore, end up as:

.box1 = 350px (100px + 250px) + 40px padding
.box2 = 225px (100px + 125px) + 40px padding
.box3 = 225px (100px + 125px) + 40px padding

Add all of these values up and you reach the magic number of 920 pixels, the width of our parent.

An important distinction to make is that the ratio refers to how the additional pixels (or unused space) are calculated, not the widths of the boxes themselves. This is why the widths are 350:225:225 pixels, and not 460:230:230 pixels.

The wonderful thing about the flexbox model is that you don’t have to remember — or even particularly understand — much of the math. While the Working Draft goes into detail on the calculation and distribution of free space, you can work safe in the knowledge that the browser will take care of this for you.

Animating Flexible Boxes

A simple and elegant effect is already at your fingertips. By making the li elements in a navigation bar flexible, and specifying their width on :hover, you can create a nice effect whereby the highlighted li element expands and all the other elements shrink. Here’s the CSS for that:

nav ul {
display: box;
width: 880px;
}

nav ul li {
padding: 2px 5px;
box-flex: 1;
-webkit-transition: width 0.5s ease-out;
min-width: 100px;
}

nav ul li:hover {
width: 200px;
}

screenshot

You’ll spot a min-width on the li element, which is used to fix a display bug in Chrome.

Equal-Height Columns: The Happy Accident!

As we’ll see, all flexbox elements inherit a default value of box-align: stretch. This means they will all stretch to fill their container.

For example, two flexbox columns in a parent with display: box will always be the same height. This has been the subject of CSS and JavaScript hacks for years now.

There are a number of practical implementations of this fortunate outcome, not the least of which is that sidebars can be made the same height as the main content. Now, a border-left on a right-hand sidebar will stretch the full length of the content. Happy days!

box-orient and box-direction

The box-orient property defines how boxes align within their parent. The default state is horizontal or, more specifically, inline-axis, which is horizontal and left-to-right in most Western cultures. Likewise, vertical is the same as block-axis. This will make sense if you think about how the browser lays out inline and block elements.

You can change the box-orient value to vertical to make boxes stack on top of each other. This is what we’ll do with the featured articles on our fruit blog.

Here is what our articles look like with box-orient set to its default setting:

screenshot

Ouch! As you can see, the articles are stacking next to each other and so run off the side of the page. It also means that they sit on top of the sidebar. But by quickly setting the parent div to box-orient: vertical, the result is instant:

screenshot

A related property is box-direction, which specifies the direction in which the boxes are displayed. The default value is normal, which means the boxes will display as they appear in the code. But if you change this value to reverse, it will reverse the order, and so the last element in the code will appear first, and the first last.

While box-orient and box-direction are essential parts of the model, they will not likely appear in the final specification, because they are being merged into the flex-direction property, which will take the following values: lr, rl, tb, bt, inline, inline-reverse, block and block-reverse. Most of these are self-explanatory, but as yet they don’t work in any browser.

box-ordinal-group

Control over the order in which boxes are displayed does not stop at normal and reverse. You can specify the exact order in which each box is placed.

The value of box-ordinal-group is set as a positive integer. The lower the number (1 being the lowest), the higher the layout priority. So, an element with box-ordinal-group: 1 will be rendered before one with box-ordinal-group: 2. If elements share the same box-ordinal-group, then they will be rendered in the order that they appear in the HTML.

Let’s apply this to a classic blog scenario: the sticky post (i.e. content that you want to keep at the top of the page). Now we can tag sticky posts with a box-ordinal-group value of 1 and all other posts with a box-ordinal-group of 2 or lower. It might look something like this:

article {
box-ordinal-group: 2;
}

article.sticky {
box-ordinal-group: 1;
}

So, any article with class="sticky" is moved to the top of the list, without the need for any front-end or back-end jiggering. That’s pretty impressive and incredibly useful.

We’ve used this code in our example to stick a recent blog post to the top of the home page:

screenshot

box-pack and box-align

The box-pack and box-align properties help us position boxes on the page.

The default value for box-align is stretch, and this is what we’ve been using implicitly so far. The stretch value stretches the box to fit the container (together with any other siblings that are flexible boxes), and this is the behavior we’ve seen so far. But we can also set box-align to center and, depending on the box-orient value, the element will be centered either vertically or horizontally.

For example, if a parent inherits the default box-align value of horizontal (inline-axis), then any element with box-align set to center will be centered vertically.

We can use this in our blog example to vertically center the search box in the header. Here’s the mark-up:

<header>
  <form id="search">
    <label for="searchterm">Search</label>
    <input type="search" placeholder="What’s your favourite fruit…" name="searchterm" />
    <button type="submit">Search!</button>
  </form>
</header>

And to vertically center the search box, we need just one line of CSS:

header {
display: box; box-align: center;
}

header #search {
display: box; box-flex: 1;
}

The height of #search has not been set and so depends on the element’s content. But no matter what the height of #search, it will always be vertically centered within the header. No more CSS hacks for you!

screenshot

The other three properties of box-align are start, end and baseline.

When box-orient is set to horizontal (inline-axis), an element with box-align set to start will appear on the left, and one with box-align set to end will appear on the right. Likewise, when box-orient is set to vertical (block-axis), an element with box-align set to start will appear at the top, and one with box-align set to end will move to the bottom. However, box-direction: reverse will flip all of these rules on their head, so be warned!

Finally, we have baseline, which is best explained by the specification:

Align all flexbox items so that their baselines line up, then distribute free space above and below the content. This only has an effect on flexbox items with a horizontal baseline in a horizontal flexbox, or flexbox items with a vertical baseline in a vertical flexbox. Otherwise, alignment for that flexbox item proceeds as if flex-align: auto had been specified.

Another property helps us with alignment: box-pack. This enables us to align elements on the axis that is perpendicular to the axis they are laid out on. So, as in the search-bar example, we have vertically aligned objects whose parent have box-orient set to horizontal.

But what if we want to horizontally center a box that is already horizontally positioned? For this tricky task, we need box-pack.

If you look at the navigation on our fruit blog, you’ll see that it’s only 880 pixels wide, and so it naturally starts at the left of the container.

screenshot

We can reposition this ul by applying box-pack to its parent. If we apply box-pack: center to the navigation element, then the navigation moves nicely to the center of the container.

screenshot

This behaves much like margin: 0 auto. But with the margin trick, you must specify an explicit width for the element. Also, we can do more than just center the navigation with box-pack. There are three other values: start, end and justify. The start and end values do what they do for box-align. But justify is slightly different.

The justify value acts the same as start if there is only one element. But if there is more than one element, then it does the following:

  • It adds no additional space in front of the first element,
  • It adds no additional space after the last element,
  • It divides the remaining space between each element evenly.

box-flex-group and box-lines

The final two properties have limited and/or no support in browsers, but they are worth mentioning for the sake of thoroughness.

Perhaps the least helpful is box-flex-group, which allows you to specify the priority in which boxes are resized. The lower the value (as a positive integer), the higher the priority. But I have yet to see an implementation of this that is either useful or functional. If you know different, please say so in the comments.

On the other hand, box-lines is a bit more practical, if still a little experimental. By default, box-lines is set to single, which means that all of your boxes will be forced onto one row of the layout (or onto one column, depending on the box-orient value). But if you change it to box-lines: multiple whenever a box is wider or taller than its parent, then any subsequent boxes will be moved to a new row or column.

Vendor Prefixes and Cross-Browser Support

It will come as no surprise to you that Internet Explorer does not (yet) support the flexbox model. Here’s how CanIUse sees the current browser landscape for flexbox:

screenshot

The good news is that Internet Explorer 10 is coming to the party. Download the platform preview, and then check out some interesting examples.

Also, we need to add a bunch of vendor prefixes to guarantee the widest possible support among other “modern” browsers. In a perfect world, we could rely on the following:

#parent {
display: box;
}

#child {
flex-box: 1;
}

But in the real world, we need to be more explicit:

#parent {
display: -webkit-box;
display: -moz-box;
display: -o-box;
display: box;
}

#child {
-webkit-flex-box: 1;
-moz-flex-box: 1;
-o-flex-box: 1;
flex-box: 1;
}

Helper Classes

A shortcut to all of these vendor prefixes — and any page that relies on the flexbox model will have many of them — is to use helper classes. I’ve included them in the source code that accompanies this article. Here’s an example:

.box {
display: -webkit-box;
display: -moz-box;
display: -o-box;
display: box;
}

.flex1 {
-webkit-flex-box: 1;
-moz-flex-box: 1;
-o-flex-box: 1;
flex-box: 1;
}

.flex2 {
-webkit-flex-box: 2;
-moz-flex-box: 2;
-o-flex-box: 2;
flex-box: 2;
}

This allows us to use this simple HTML:

<div class='box'>
  <div class='flex2' id="main">
   <!-- Content here -->
 </div>
  <div class="flex1" id="side”>
    <!-- Content here -->
  </div>
</div>

Using non-semantic helper classes is considered bad practice by many; but with so many vendor prefixes, the shortcut can probably be forgiven. You might also consider using a “mixin” with Sass or Less, which will do the same job. This is something that Twitter sanctions in its preboot.less file.

Flexie.js

For those of you who want to start experimenting with flexbox now but are worried about IE support, a JavaScript polyfill is available to help you out.

Flexie.js, by Richard Herrera, is a plug-and-play file that you simply need to include in your HTML (download it on GitHub). It will then search through your CSS files and make the necessary adjustments for IE — no small feat given that it is remapping much of the layout mark-up on the page.

screenshot

A Word on Firefox

The flexbox model was, at least originally, based on a syntax that Mozilla used in its products. That syntax, called XUL, is a mark-up language designed for user interfaces.

The irony here is that Firefox is still catching up, and its rendering of some flexbox properties can be buggy. Below are some issues to watch out for, which future releases of Firefox will fix. Credit here must go to the uber-smart Peter Gasston and Oli Studholme, giants on whose shoulders I stand.

  • Flexbox ignores overflow: hidden and expands the flexbox child when the content is larger than the child’s width.
  • The setting display: box is treated as display: inline-box if there is no width.
  • The outline on flexbox children is padded as if by a transparent border of the same width.
  • The setting box-align: justify does not work in Firefox.
  • If you set box-flex to 0, Firefox forces the element to act like it’s using the quirks-mode box model.

Summary

The flexbox model is another exciting development in the CSS3 specification, but the technology is still very much cutting-edge. With buggy support in Firefox and no support in Internet Explorer until version 10 moves beyond the platform preview, it is perhaps of limited use in the mainstream.

Nevertheless, the spec is still a working document. So, by experimenting with these new techniques now, you can actively contribute to its development.

It’s hard to recommend the flexbox model for production websites, but envelopes need pushing, and it might well be the perfect way to lay out a new experimental website or idea that you’ve been working on.

Offering a range of new features that help us break free of the float, the flexbox model is another step forward for the layout of modern Web pages and applications. It will be interesting to see how the specification develops and what other delights for laying out pages await the Web design community in the near future.


© Richard Shepherd for Smashing Magazine, 2011.

 

Any suggestion/comment/feedback/question is welcome. We offer tech support for any website/design related issues so if you are facing any problem, contact us now. We only charge if we resolve the issue.

Symbols In Illustrator CS5 : An indepth study


For drawing and painting digital illustrations, Adobe Illustrator is a favorite among designers for many reasons. One of the reasons is some of the amazing time-saving features that come with it. The Symbols feature in Illustrator does just this: it saves valuable time by creating a “symbol,” or copy, of an object. This means that all of the time you have spent creating a minutely detailed flower does not have to be repeated. Instead, simply save the flower as a symbol for future use. Plus, symbols greatly reduce the size of image files.

Illustrator makes it easy to use symbols multiple times within a document as well. With the Symbols tools, you can add and alter several symbols at once. And in CS5, you can now change the settings for a symbol while editing. Another benefit of symbols in Illustrator CS5 is that you can change a symbol to a movie clip, making it easy to export to Adobe Flash. You can also make sure that the symbol scales correctly for your interface design by choosing 9-Slice Scaling while still in Illustrator.

CS5 makes working with symbols even easier by adding a few new features, explained below. If you are working in an earlier version of Illustrator, you will still be able to follow along and become as much a master of symbols in Illustrator as the next guy.

The topics covered in this article are:

  1. Basic Symbol Use
    • Symbols panel 101
    • Creating symbols
    • Symbol libraries
    • Placing symbols
    • Breaking links
    • Changing symbol options
    • Adding or duplicating symbols
    • Deleting symbols
    • Redefine a symbol
    • Swap/replace a symbol
  2. Advanced Symbol Use
    • Control window
    • Editing as a graphic
    • Registration point edits
    • 9-Slice Scaling edits
    • Sub-layer for symbols
  3. Symbolism Tools
    • Symbol sets
    • Symbol Sprayer tool
    • Symbol Shifter tool
    • Symbol Scruncher tool
    • Symbol Sizer tool
    • Symbol Spinner tool
    • Symbol Stainer tool
    • Symbol Screener tool
    • Symbol Styler tool
  4. Symbolism Tools Advanced Options
    • Options available to all symbol tools
    • Symbol Sprayer options
    • Symbol Sizer options
  5. Make Symbols Your Best Friend
    • More resources

Basic Symbol Use

Some of the actions for Symbols are quite easy to figure out just by playing around with them, while others take some explanation. Below is an overview of how to use symbols, but remember that you can move, scale, rotate, reflect and skew (shear) symbols just like other objects.

Symbols Panel 101

To open the Symbols panel, click on the button that looks like a clover, located in the menu on the right side of the Illustrator screen. Or go to WindowSymbols. As always the case with Adobe software, there are several ways to complete a task with Symbols.

The drop-down menu in the upper-right corner of the Symbols panel offers access to nearly every action for the panel, including creating a symbol, editing a symbol, breaking links, changing the view in the panel and more. To save you time, along the bottom of the Symbols panel are a few shortcuts to the most commons actions. You can also use the options in the Control window at the top of the screen.

To select a symbol in the panel, click on the icon. With a symbol selected, you can now edit it, place it on your artboard, delete it and more.

You can also organize the symbols in the panel by clicking and dragging them around. Or choose “Sort by Name” to change the view of the icons from within the drop-down menu.

Creating Symbols

Nearly any object can be made into a symbol. A couple of exceptions are art that is not linked and groups of graphics. Make sure the Symbols panel is open.

Click on the “New Symbols” icon (it looks like two white squares, one smaller than the other) at the bottom of the Symbols window, or drag an object directly into the Symbols panel. Illustrator will automatically turn the object you have selected into a symbol and also add the object to the Symbols window.

If you do not want your original object to become a symbol, then hold down Shift while creating the new symbol. This allows you to quickly create a symbol while retaining editable work on your artboard.

In the Symbols dialog box that appears, first specify a name, one that you will easily remember later.

Next, select the “Type” of symbol you want to create: a graphic or movie clip. If you will be using the symbol only in Illustrator, it does not matter which you select. The only reason why the two options are available is if you want to use the symbol in Adobe Flash: a movie-clip symbol in Flash can be manipulated for animation purposes, while a graphic symbol in Flash will remain static.

Symbol Libraries

The Symbol Libraries provide a clean way to organize the symbols that you acquire. To open them, click on the Symbols Library menu in the far left of your Symbols tools, or go to WindowSymbol Libraries[symbol]. The library that you select will open in a new window. When you choose a symbol from an open library, it is automatically added to the Symbols panel.

Remember that you can change the symbol once it is in your panel, but the original symbol in the library will never change.

Adding symbols from the panel to your library is easy but can be confusing at first. Begin by deleting any symbols that you do not want to add. (To quickly remove unused symbols, choose “Select All Unused” from the Symbols panel menu.) Then choose “Save Symbols” from the Symbols Library menu button, or go to the Symbols panel menu and select “Save Symbol Library.” Name your symbol library, and save it to the default Symbols folder. You can now find your new library folder in Symbols Library MenuUser Defined[symbol].

Note: You can create a new library from any symbols, whether default Illustrator symbols or your own. Just drag the desired symbols into the Symbols panel, and follow the steps above to create a new library.

Saving symbol libraries in locations other than the default library folder enables you to more easily share your created symbols with other designers. First, create your library as explained in the section above. When you get to the step where Illustrator asks you to choose a name and location for your library, choose a location other than the default folder (such as the desktop or “My Documents”). Remember that you can always access the symbols in this alternate location when working in Illustrator by choosing “Other Library” from the Symbols Library menu.

Placing Symbols

To place a symbol on your artboard, simply click on the icon in the panel and drag the symbol onto your board, or select the Symbol icon in the panel and then click the “Place Symbol Instance” button. Dragging the symbol is helpful if you have a specific place for it, whereas the “Place Symbol Instance” button works well when you want to place several on the board but are not yet sure where.

Breaking Links

The “Break Link to Symbol” button simply turns the symbol that you’ve placed on your artboard back into a regular graphic. While changes such as move, scale, rotate, reflect and skew (shear) can be made to a symbol’s instance on the artboard without changing the original symbol in the panel, more advanced edits will affect both the instance and the symbol if they are linked. By clicking on the “Break Link to Symbol” button, you can now modify the symbol in the panel without affecting the graphic on your artboard. The opposite is also true: edits made to an instance with a broken link will no longer affect the symbol.

Changing Symbol Options

The “Symbol Options” button opens the Options dialog box, where you can change the symbol to “Graphic” or “Movie Clip,” change it to 9-Slice Scaling, and make the symbol automatically align to a grid. See the section above on “Creating Symbols” for more explanation. You can also change the name, which is helpful if you duplicate a symbol.

Adding or Duplicating Symbols

The “New Symbol” button allows you to change a selected object into a symbol. Or, to quickly duplicate a symbol, just select it in the panel and drag it onto the “New Symbol” button. Illustrator will automatically name it the original symbol’s name plus a number, such as “Cube 1,” but you can change the name with the Options button.


Drag the symbol to the “New Symbol” button.


A new symbol will appear with a numbered name.

Deleting Symbols

Drag a symbol onto the Delete button to delete it from the panel. This will not delete it from your library, so if you need to use it again, just open the library and drag it back onto the panel. You can also click on the “Delete” button when a symbol is selected to delete it; a dialog box will appear asking “Delete the selected symbol?”

If you delete a symbol that has instances on the artboard, an alert dialog box will appear saying that the symbol cannot be deleted until its instance in use is either deleted or expanded. Choose “Expand Instances” to break the link to the symbol; this option will turn the instance on the artboard into a regular graphic and will delete the symbol from the panel. Choose “Delete Instances” to remove the instance from the artboard and delete the symbol from the panel.

Redefine Symbol

“Redefine Symbols” (located in the drop-down menu of the Symbols panel) allows you to change a symbol to the selected graphic on your artboard. Keep in mind that this action will change only the appearance of the symbol, while the name and other options (such as the type) will remain the same.


With the symbol selected on the artboard, select one of the previously defined symbols in the Symbols panel. In this example, we have selected the bow-tie symbol.


The bow-tie symbol now looks like the grime symbol, but the name and other options remain unchanged.

Swap/Replace a Symbol

To swap a symbol with another, select the symbol on your artboard, then select the symbol icon in the panel that you want to use in its place. From the drop-down menu, select “Replace Symbol.”

2. Advanced Symbol Use

Symbols can be edited several ways. In fact, CS5 now offers more editing options than previous versions of Illustrator, including 9-Slice Scaling (see below) and much more.

Control Window

One way to edit symbols is with the options in the Control window, located along the top (or bottom, depending on how you have arranged your Illustrator window) of your artboard. Simply click on the symbol that you want to edit, and you will notice that many of the Control window options for symbols are similar to the options for other objects, such as “Opacity,” “Recolor Artwork,” “Transform” and “Align to Selection.” You might also notice that you can break links and replace symbols from this menu.


The Control window’s options change depending on what type of graphic is selected, so some of these options are available to normal graphics, while others are exclusive to symbols.

To undo transformations, just select the symbol on the artboard and click “Reset” on the Control window; or choose “Reset Transformation” from the drop-down menu in the Symbols panel; or simply right-click on the symbol’s instance on the artboard and choose “Reset Transformation” from the context menu.

Editing as a Graphic

To edit a symbol with your primary editing tools just as you would any other graphic, click on a symbol in the panel (or, to be safe, duplicate the symbol and then edit the duplication), and select “Edit Symbol” in the drop-down menu. (Alternatively, double-click on the symbol in the panel.) You will now be able to modify the symbol in your panel as well as any instances on your artboard.

To modify only the instance(s) on your artboard and not the symbol in your panel, select the instance(s) on the artboard and break the link first. The instance will now be regular artwork that you can edit using any tool in the Tool menu.

You can always turn your edited graphic back into a new symbol by selecting the graphic and clicking “New Symbol” in the symbol’s palette.

To break links to all symbol instances at once, select the symbol’s icon in the Symbols panel, then choose “Select All Instances” from the drop-down menu.

You can also edit all symbol instances along with the symbol in the panel. Simply double-click the symbol on the artboard; or select the instance and click the “Edit Symbol” button in the Control window; or select “Edit Symbol” from the fly-out menu. An alert dialog box will appear, warning you that you are about to edit the symbol and that any changes will be made to all instances of that symbol.

You can choose “OK” or “Cancel.” This means what it says: all instances and the symbol in the panel will be changed according to the edits you make while in this “Isolation Mode.” Check the “Don’t Show Again” checkbox to prevent this warning from appearing again.

To exit the Edit Symbol mode, click on the “Back” arrow in the edit bar at the top of the artboard, or hit the “Escape” key. You can also right-click on the instance that you are editing and choose “Exit Isolation Mode.”

Registration Point Edits

In CS5, editing the registration point of symbols is possible. For those of you familiar with Flash, no more explanation is needed. For those who know nothing of Flash, the registration point basically allows you to select where to place the anchor point, which determines how a symbol will be placed within a screen coordinate.

One time when the registration grid makes a difference in Illustrator is when rotating symbols. If your registration is set to the upper-right corner of your symbol, then the symbol will rotate around that corner. You can see the location of the registration point simply by selecting the symbol on the artboard using the Selection tool. It looks like a small crosshair.

You can set the registration point by selecting a point on the registration grid when you create a new symbol. In the example below, the registration is set to the bottom-left corner. The default is centered. Just click the “New Symbol” button, and the Symbol options dialog box will pop up.

To edit the registration point or to fine tune the location, simply double-click the symbol on the artboard, and you will enter Isolation Mode. Move the graphic around; the registration point will remain stationary. When finished, click the “Back” button in the Control window. In this example, the symbol has been moved to the left, which has the effect of shifting the registration point to the right on the symbol.

Illustrator automatically uses the registration grid’s settings on a symbol, but you can turn this off. Say that you want to set the registration point to the left side of a symbol for Flash purposes, but while in Illustrator you do not want to use the grid. With the symbol selected, click on “Transform” in the Control window. Then click on the drop-down menu in the upper-right corner of the Transform panel. From this menu, select “Use Registration Point for Symbol.” With it deselected, this setting is now off.

9-Slice Scaling Edits

You can select 9-Slice Scaling for a symbol, either when you first create it or later through the Symbol options.

You can also edit the 9-Slice Scaling grid on a symbol when in “Edit (Isolation) Mode.” Double-click the symbol on the artboard to enter “Edit (Isolation) Mode.” Then hover the Selection tool over any of the gridlines until it changes to the move cursor.

Sub-Layers for Symbols

In CS5, you can now create sub-layers for symbols. The reason this is possible is that CS5 has given symbols an independent layer hierarchy, even when you expand symbols. Also, the “Paste Remember Layers” setting works when pasting objects in the symbol’s Edit Mode.

3. Symbolism Tools

One of the best aspects of symbols in Illustrator is the Symbol tools (referred to as “Symbolism Tools” by Adobe). Using symbol sets and the tools available, designing even the most detailed graphics is quick and easy.

Symbol Sets

Although you can use the Symbolism tools in a single symbol’s instance, they really shine when you use them with symbol sets. A symbol set is a group of symbol instances, often sprayed onto the artboard using the Symbol Sprayer tool. To select an entire set, just click on that symbol’s icon in your panel, or click on more than one symbol icon to select more than one symbol set.


In this example, a symbol has been sprayed onto the artboard. To select the set, simply use the Selection tool, and click on any of the symbols.

Symbol Sprayer Tool

With the Symbol Sprayer tool, you can add single instances, add single or multiple sets of instances, and delete individual or sets of symbol instances. To spray symbol instances onto the artboard, select the symbol from the panel, select the Symbol Sprayer tool from the toolbar, and click to add one instance at a time, or drag to spray several at a time.

To delete symbols from the artboard, hold down Alt or Option while clicking or dragging on the instances that you want to remove.

Symbol Shifter Tool

To move entire sets of symbols, use the Symbol Shifter tool. Just select the set or individual symbol instances that you want to shift, and with the Symbol Shifter tool selected, drag the instances in any direction on the board. You can also change the stacking order of symbols with this tool. Simply hold down Shift while clicking on an instance or a set to move it forward. Hold down Alt/Option + Shift while clicking on an instance or set to move it backward.

Symbol Scruncher Tool

The Scruncher tool is helpful for when you want to adjust the space between symbols in a set. To move symbol instances closer together, select the Symbol Scruncher tool, and click or drag in the areas between symbols. To push symbols apart, hold down Alt/Option while clicking or dragging between symbols.

Symbol Sizer Tool

Quickly resize entire sets of symbols by selecting the Symbol Sizer tool and then clicking or dragging on the symbols in the set that you want to resize. Keep in mind that only those symbols within the brush’s dimensions will change size. To decrease in size, hold down Alt/Option while clicking or dragging on symbol instances.

Hold down Shift while clicking or dragging the tool over several symbols in the set to preserve their density. You have to be careful with this shortcut, though. If you are enlarging symbols and hold down Shift, they will often be deleted to keep the density the same. But if you are downsizing symbols and use the Shift key, more symbols of the same size will be added to the set.

Symbol Spinner Tool

Another way to create variety in a symbol set made up of the same symbols is to select the Symbol Spinner tool and rotate the symbols in different directions. Click on a group of symbols and drag and rotate the cursor to turn the symbols in different directions.

Keep in mind that, just as when using the Rotate tool on symbol instances, with the Symbol Spinner tool, instances in a set will rotate based on the registration grid settings. So, if you’ve selected the upper-right corner of the registration grid when creating symbols, then your symbols will “lock” on the upper-right corner and rotate around that locked position.

Symbol Stainer Tool

This is an incredible tool for creating a naturally random color variety within a symbol set. It uses both the color’s hue and luminosity to “stain” symbol instances. Therefore, both black symbols (low luminosity) and white symbols (high luminosity) do not change at all; the higher or lower the luminosity, the less drastic the change in color.

First, you will need to select a staining color from the Color panel. With the Symbol Stainer tool selected, click or drag across the symbol instances that you want to colorize. If you want to reverse the stain effect, hold down Alt/Option and click or drag across symbols.

With the Stainer tool, the longer you hold it over a symbol set, the greater the amount of tint change. But if you want the same amount of tint no matter how much you drag the tool across a symbol set, hold down Shift. This works well when you want to change an entire set to a new shade without much variation.

Symbol Screener Tool

To change the transparency of symbol instances, select the Symbol Screener tool and click or drag across symbols. Hold down Alt/Option to reverse the transparency effect.


In this example, we have duplicated the Symbol layer several times and used the Symbol Stainer tool to add color depth. The Symbol Screen tool allows us to tone down the effect.

Symbol Styler Tool

The Symbol Styler tool allows you to add or remove graphic styles from symbol instances. First, select the Symbol Styler tool (if you select a graphic style first, then Illustrator will apply the graphic style to the entire selected symbol set). Then choose a graphic style from the Graphic Styles panel by going to WindowGraphic Styles, and click or drag across symbol instances for a gradual increase in a graphic style.

Hold down Alt/Option while clicking or dragging to reverse the style effect. Keep in mind that if you want to keep the graphic style changes the same throughout the symbol set, hold down Shift while using the Symbol Styler tool.


Here, we’ve opened a standard Graphics Style library called Illuminate Styles, by going to Windows → Graphic Styles Library → Illuminate Styles.

4. Symbolism Tools Advanced Options

To access the Symbolism tool’s options, double-click on any of the tools. It doesn’t matter which tool you double-click, because all of them can be accessed from the Options dialog box.

Options Available to All Symbolism Tools

At the top of the dialog box are options that stay the same, no matter which tool is selected. Some are fairly self-explanatory. “Diameter” determines the brush size. “Intensity” sets the change rate. “Symbol Set Density” sets the amount of symbols placed within a given area based on a formula; the higher the number, the denser the symbols will be.

“Method” (not available for all tools) adjusts the symbol’s instances: “User Defined” allows a gradual adjustment, determined by the location of the cursor; “Random” adjusts the symbols at a random rate; and “Average” smoothens the symbols gradually. Select “Show Brush Size and Intensity” to see these options while using the tools.

Click on each of the tool icons within the options dialog box to see individual adjustments and shortcuts. Not all of the tools have adjustments, and not all have shortcuts.

Symbol Sprayer Options

The Symbol Sprayer tool contains the most options. All six options contain two choices: “User Defined” and “Average.” If you already have symbol instances in place, the “Average” setting allows the sprayer to spray according to the settings of instances within the brush’s area. For example, with “Average” as the setting, spraying next to instances with variegated sizes will cause your symbol’s instances to spray in variegated sizes, depending on which ones fall within the brush’s radius.

“User Defined” means that the sprayer will place symbols using preset settings:

  • Scrunch”: The density based on the size of the original symbol.
  • Size”: Once again, based on the original symbol size.
  • Spin”: Symbols will orient themselves based on the movement of the mouse.
  • Screen”: 100% opacity automatically.
  • Stain”: A full amount of tint and the current color of the symbol.
  • Style”: This is determined by the current style of the symbol.

Symbol Sizer Options

The Symbol Sizer options include only two choices. When the “Proportional Resizing” checkbox is selected, the symbol instance’s size will remain uniform when resizing. When “Resizing Affects Density” is selected, the symbol’s instances will move further away when enlarged and closer together when shrunk.

5. Make Symbols Your Best Friend

If you plan to create illustrations that repeat a lot of graphics, such as trees, grass, flowers, floating shapes and swirls, to name a few, then symbols should become your best friend in Illustrator. Rather than just copying and pasting a graphic that you have created, you can use a symbol to quickly spray hundreds to millions of copies on your artboard and make changes to them in a matter of minutes. Even if you have used symbols before, taking the time to really play around with them and maybe even following some tutorials will help you grasp this gem of an Illustrator tool.

© Tara Hornor for Smashing Magazine, 2011.

Any suggestion/comment/feedback/question is welcome. We offer tech support for any website/design related issues so if you are facing any problem, contact us now. We only charge if we resolve the issue.

With CSS animation now supported in both Firefox and Webkit browsers, there is no better time to give it a try. Regardless of its technical form, whether traditional, computer-generated 3-D, Flash or CSS, animation always follows the same basic principles. In this article, we will take our first steps with CSS animation and consider the main guidelines for creating animation with CSS. We’ll be working through an example, building up the animation using the principles of traditional animation. Finally, we’ll see some real-world usages.

screenshot

CSS Animation Properties

Before diving into the details, let’s set up the basic CSS:

Animation is a new CSS property that allows for animation of most HTML elements (such as div, h1 and span) without JavaScript or Flash. At the moment, it’s supported in Webkit browsers, including Safari 4+, Safari for iOS (iOS 2+), Chrome 1+ and, more recently, Firefox 5. Unsupported browsers will simply ignore your animation code, so ensure that your page doesn’t rely on it!

Because the technology is still relatively new, prefixes for the browser vendors are required. So far, the syntax is exactly the same for each browser, with only a prefix change required. In the code examples below, we use the -webkit syntax.

All you need to get some CSS animation happening is to attach an animation to an element in the CSS:

/* This is the animation code. */
@-webkit-keyframes example {
   from { transform: scale(2.0); }
   to   { transform: scale(1.0); }
}

/* This is the element that we apply the animation to. */
div {
   -webkit-animation-name: example;
   -webkit-animation-duration: 1s;
   -webkit-animation-timing-function: ease; /* ease is the default */
   -webkit-animation-delay: 1s;             /* 0 is the default */
   -webkit-animation-iteration-count: 2;    /* 1 is the default */
   -webkit-animation-direction: alternate;  /* normal is the default */
}

First, we have the animation code itself. This can appear anywhere in the CSS, as long as the element that you’re animating can find the relevant animation-name.

When assigning the animation to your element, you can also use the shorthand:

div {
-webkit-animation: example 1s ease 1s 2 alternate;
}

We can cut this down further by not entering all of the values. Without a value specified, the browser will fall back to the default.

Those are the basics. We’ll work through more code in the following section.

Applying Principles of Traditional Animation

Disney — the masters of traditional animation, in my opinion — developed the 12 principles of traditional animation early on and documented them in its famous book The Illusion of Life. These basic principles can be applied to all manner of animation, and you needn’t be an expert in animation to follow along. We’ll be working through an example of CSS animation that uses the 12 principles, turning a basic animation into a more believable illusion.

These may just be bouncing balls, but you can see a world of difference between the two versions.

This example demonstrates the features of CSS animation. In the code below, we use empty divs to show how it works; this isn’t the most semantic way to code, as we all know, but the point is to show how simple it is to bring a page to life in a way that we haven’t been able to do before in the browser.

Squash and Stretch

screenshot

The crude bouncing ball is a great demonstration of this first point. If the ball falls at a high velocity and hits the floor, you’ll see it squash down from the force and then stretch back out as it bounces up.

At a basic level, this should give our animation a sense of weight and flexibility. If we dropped a bowling ball, we wouldn’t expect it to flex at all — it might just damage the floor.

We can apply this squash and stretch effect through a CSS3 property, transform:

@-webkit-keyframes example {
   0% { -webkit-transform: scaleY(1.0); }
   50% { -webkit-transform: scaleY(1.2); }
   100% { -webkit-transform: scaleY(1.0); }
}

This will scale the object lengthwise (on the y axis, up and down) to 1.2 times the original size, and then revert to the original size.

We’re also using more complex timing for this animation. You can use from and to for basic animations. But you can also specify many actions for your animation using percentages, as shown here.

That covers the squashing. Now we need to move the object using translate. We can combine transforms together:

50% {
-webkit-transform: translateY(-300px) scaleY(1.2);
}

The translate property allows us to manipulate the object without changing any of its base properties (such as position, width or height), which makes it ideal for CSS animation. This particular translate property makes it look like the ball is bouncing off the floor at the mid-point of the animation.

(Please note: to view the sample animations, you’ll need the latest version of Firefox, Chrome or Safari. At the time of writing, Safari provides the best viewing experience of CSS animation.)

  • View Squash and Stretch in action.
  • http://dl.dropbox.com/u/12132497/12-principles/1.html

Yes, it still looks rubbish, but this small adjustment is the first step in making this animation more believable.

Anticipation

Anticipation adds suspense, or a sense of power, before the main action. For example, the bend in your legs before you jump helps viewers anticipate what will come next. In the case of our bouncing ball, simply adding a shadow beforehand suggests that something is falling from above.

  • View Anticipation in action.
  • http://dl.dropbox.com/u/12132497/12-principles/2.html

We’ve added another div for the shadow, so that we can animate it separate from the ball.

To create anticipation here, we keep the ball from dropping into the scene immediately. We do this simply by adjusting the percentage timings so that there is no movement between the start point and the first action.

@-webkit-keyframes example {
   0% { -webkit-transform: translateY(-300px) scaleY(1.2); }
   35% { -webkit-transform: translateY(-300px) scaleY(1.2); } /* Same position as 0% */
   65% { -webkit-transform: translateY(0px) scaleY(1.2); }    /* Starts moving after 35% to this position */
   67% { -webkit-transform: translateY(10px) scaleY(0.8); }
   85% { -webkit-transform: translateY(-100px) scaleY(1.2); }
   100% { -webkit-transform: translateY(0px); }
}

At the 35% point of the animation, the ball is in the same location, positioned off the stage, not moving. Then, between 35% and 65%, it suddenly moves onto the stage, and the rest of the animation follows.

You can also use animation-delay to create anticipation:

div {
-webkit-animation-delay: 1s;
}

However, this could have an undesired effect. The animation-delay property simply ignores any animation code until the specified time. So, if your animation starts in a position different from the element that you are animating, then the object will appear to suddenly jump as soon as the delayed animation starts.

This property works best for looping animations that begin and end in the same location.

Staging

screenshot

Try to give a stage to the scene; put the animation in context. Thinking back to Disney films, what would they be without the fantastic background artwork? That’s half of the magic!

The stage is also key to focusing attention. Much like on a theater stage, lighting will be cast on the most important area. The stage should add to the illusion. With our bouncing ball, I’ve added a simple background to focus on where the ball will land. Now the viewer knows that the action will take place in the center, and the scene is no longer lost in snow.

Straight-Ahead vs. Pose to Pose

In traditional animation, this is a choice in how to construct your animation. The straight-ahead option is to draw out every frame in the sequence. The pose-to-pose option is to create a few keyframes throughout the sequence, and then fill in the gaps later. Filling in these gaps is known as “in-betweening,” or “tweening,” a familiar term for those used to animating in Flash.

With CSS animation, we typically use the latter, pose to pose. That is, we’ll add keyframes of action, and then the browser will “tween” the intermediate frames automatically. However, we can learn from the straight-ahead technique, too. The browser can do only so many effects; sometimes, you have to do it the hard way and put in more animation hard-graft to get the desired effect.

Follow-Through and Overlapping

Also known as physics! Follow-through and overlapping are more commonly used in character animation for body movement, such as to show arms swaying as the character drops them or long hair falling. Think of someone with a big stomach turning quickly: their body will turn first, and their bulging gut will follow shortly after.

For us, this means getting the physics right when the ball drops. In the demonstrations above, the ball drops unnaturally, as if beyond the control of gravity. We want the ball to drop and then bounce. However, this is better achieved through the next principle.

Slow In and Out

This has to do with speeding up and slowing down. Imagine a car that is speeding along and has to come to a stop. If it were to stop instantly, it wouldn’t be believable. We know that cars take time to slow down, so we would have to animate the car braking and slowly coming to a stop.

This is also relevant to showing the effect of gravity. Imagine a child on a swing. As they approach the highest point, they will slow down. As they come back down and gain speed, their fastest point will be at the bottom of the arc. Then they will rise up on the opposite side, and the action repeats.

screenshot

Back to our example, by adjusting the in and out speeds, we can make the ball much more believable (finally).

When the ball hits the floor, the impact will make it bounce back up instantly. As it reaches its highest point, it will slow down. Now it looks like the ball is really dropping.

In CSS, we can control this with the animation-timing-function property:

-webkit-animation-timing-function: ease-out;

This property takes the following values:

  • ease-inSlow at the beginning, and then speeds up.
  • ease-outFast at the beginning, and then slows to a stop.
  • ease-in-outStarts slow, speeds up in the middle, and then slows to a stop.
  • linearMoves at an even speed from start to finish.

You can also use the bezier-curve function to create your own easing speeds.

  • View Slow in and out in action.
  • http://dl.dropbox.com/u/12132497/12-principles/6.html

Arcs

screenshot

Similar to the follow-through principle of physics, arcs follow the basic principle of “what goes up must come down.” Arcs are useful in thinking about the trajectory of an object.

Let’s throw the ball in from the left of the stage. A convincing animation would predict the arc along which the ball will fall; and in our example it will have to predict the next arc along which the ball will fall when it bounces.

This animation can be a bit more fiddly to adjust in CSS. We want to animate the ball going up and down and side to side simultaneously. So, we want our ball to move in smoothly from the left, while continuing the bouncing animation that we’ve been working on. Rather than attempt to capture both actions as one animation, we’ll do two separate animations, which is easiest. For this demonstration, we’ll wrap our ball in another div and animate it separately.

The HTML:

<div class="ball-arc">
   <div class="ball"></div>
</div>

And the CSS:

.ball-arc {
-webkit-animation: ball-x 2.5s cubic-bezier(0, 0, 0.35, 1);
}
   /* cubic-bezier here is to adjust the animation-timing speed.
   This example makes the ball take longer to slow down. */

@-webkit-keyframes ball-x {
   0% { -webkit-transform: translateX(-275px); }
   100% { -webkit-transform: translateX(0px); }
}

Here, we have one animation to move the ball sideways (ball-x) and another animation to bounce the ball (ball-y). The only downside to this method is that if you want something really complex, you could end up with a code soup with poor semantics!

  • View Arcs in action.
  • http://dl.dropbox.com/u/12132497/12-principles/7.html

Secondary Action

A secondary action is a subtlety that makes the animation much more real. It addresses the details. For example, if we had someone with long hair walking, the primary action would be the walking, and the secondary action would be the bounce of the hair, or perhaps the ruffling of the clothes in the wind.

In our example, it’s much simpler. By applying more detail to the ball, we make the secondary action the spinning of the ball. This will give the illusion that the ball is being thrown in.

Rather than add another div for this animation, we can be more specific by adding it to the new img element that we’re using to give the ball texture.

.ball img {
-webkit-animation: spin 2.5s;
}

@-webkit-keyframes spin {
   0% { -webkit-transform: rotate(-180deg); }
   100% { -webkit-transform: rotate(360deg); }
}
  • View Secondary action in action.
  • http://dl.dropbox.com/u/12132497/12-principles/8.html

Timing

screenshot

This is simply the timing of your animation. The better the timing of the animation, the more realistic it will look.

Our ball is a perfect example of this. The current speed is about right for a ball this light. If it were a bowling ball, we would expect it to drop much more quickly. Whereas, if the animation were any slower, then it would look like we were playing tennis in space. The correct timing basically helps your animation look realistic.

You can easily adjust this with the animation-duration property, and you can adjust the individual timings of your animation using percentage values.

Exaggeration

Cartoons are known for exaggeration, or impossible physics. A cartoon character can contort into any shape and still manage to spring back to normal. In most cases, though, exaggeration is used for emphasis, to bring to life an action that would otherwise look flat in animation.

Nevertheless, use exaggeration modestly. Disney had a rule to base its animations on reality but push it slightly further. Imagine a character running into a wall; its body would squash into the wall more than expected, to emphasize the force of impact.

We’re using exaggeration in combination with squash and stretch to make it really obvious when the ball hits the floor. I’ve also added a subtle wobble to the animation. Finally, we also stretch the ball in and out as it bounces up and down to emphasize the speed.

Just as when we added one animation onto another, here we’ll add another div, which will wobble in sync with the ball hitting the floor:

@-webkit-keyframes wobble {

0%, 24%, 54%, 74%, 86%, 96%, 100% {
   -webkit-transform: scaleX(1.0);
/* Make the ball a normal size at these points */
}

25%, 55%, 75% {
   -webkit-transform: scaleX(1.3) scaleY(0.8) translateY(10px);
/* Points hitting the floor: squash effect */
}

30%, 60%, 80% {
   -webkit-transform: scaleX(0.8) scaleY(1.2);
/* Wobble inwards after hitting the floor */
}

75%, 87% {
   -webkit-transform: scaleX(1.2);
/* Subtler squash for the last few bounces */
}

97% -webkit-transform: scaleX(1.1);
/* Even subtler squash for last bounce */
}

}

The code looks more complex than it is. It’s simple trial and error. Keep trying until you get the right effect!

  • View principle 10 (exaggeration) in action.
  • http://dl.dropbox.com/u/12132497/12-principles/10.html

Solid Drawing and Appeal

I have nothing more to teach you… at least not in code. These final two animation principles cannot be shown in code. They are skills you will have to perfect in order to make truly amazing animations.

When Disney started production on Snow White, it had its animators go back to life drawing classes and learn the human form again. This attention to detail is evident in the film, which goes to show that good animation requires solid drawing skills and sound knowledge of the form you are animating.

Most CSS animation will likely not be as complex as intricate figure animations, but the basic principle holds true. Whether a door is opening to reveal content or a “contact us” envelope is being sealed and delivered, the animation should be believable, not robotic… unless you’re animating a machine.

The appeal, or charisma, of each character will be unique. But as Disney has always shown, anything can have character: a teapot, a tree, even spoons. But with CSS, consider how the overall animation will contribute to the design and make the overall experience more satisfying. We don’t want to make clippy animations here.

Go Forth And Animate!

CSS animation is a great new feature. As with every new CSS feature, it will be overused and misused at first. There is even the slight danger that we’ll see a return of those long-winded Flash-style animated splash pages. Although I have faith in the Web community not to do this.

CSS animation can be used to really bring a website to life. While the code for our bouncing ball may not be the most semantic, it hopefully shows how simple it can be to bring almost anything on the page to life with CSS.

It can bring much-needed interaction to your elements (sans Flash!); it can add excitement to the page; and in combination with JavaScript, it can even be an alternative way to animate for games. By taking in the 12 principles above and working away at your animation, you can make your websites more convincing, enticing and exciting, leading to a better experience overall.

CSS Animation Tools

While knowing the CSS itself is great, plenty of tools are popping up that will help you animate. The 12 principles apply regardless, but if you’re worried about the code, these great tools let you try out CSS animation without getting too technical.

  • Sencha Animator
  • Adobe Edge
  • Tumult Hype (Mac only)

© Tom Waterhouse for Smashing Magazine, 2011.

Any suggestion/comment/feedback/question is welcome. We offer tech support for any website/design related issues so if you are facing any problem, contact us now. We only charge if we resolve the issue.

Any suggestion/comment/feedback is welcome. We offer tech support for any website/design related issues so if you are facing any problem, contact us now. We only charge if we resolve the issue.


Today we are glad to release a yet another freebie: a Facebook Fan Page GUI PSD, designed by Hike and released for Smashing Magazine and its readers. The PSD will speed up the process of creating previews, thus sparing you from drawing all the comps and letting you customize all the texts, buttons and data as you need. All layers are vectorized, allowing you to scale up the GUI without loss of quality. The mock-up is 100% pixel-accurate, it has 4 viewing modes (default wall, wireframe wall, default tab, wireframe tab), all layers labeled and grouped. Smart guides are included. The PSD is compatible with Adobe Photoshop CS3+.

With every update Facebook performs to its fan page design, Hike reproduces it 24 hours later and updates its download link with the latest version. The main idea behind this PSD was to provide all designers and agencies with a useful tool that will improvs their daily workflow when it comes to preparing Facebook-related previews for their clients or internal presentations. As usual, the goodie is absolutely free to use in private and commercial projects.

Download the PSD for free!

You can use the freebie for all your projects for free and without any restrictions. Please link to this article if you want to spread the word. You may modify the file as you wish.

Screenshot

Features

  • 100% pixel-accurate
  • 4 viewing modes (default wall, wireframe wall, default tab, wireframe tab)
  • Fully vectorized
  • Limitless scaling
  • All layers labeled
  • Smartly grouped
  • Completely editable
  • Includes smart guides
  • CS3+ compatible
  • Always up to date

Previews

tab_wireframe
Tab wireframe (large preview)

wall_default
Default wall (large preview)

wall_wireframe
Wall wireframe (large preview)

layerpalette
Layer Pallett (large preview)

Behind the Design

As always, here are some insights from the designer:

“From our own experience we knew how time consuming it could be to have to recreate or prepare a decent Facebook template that allows you to implement custom tab graphics, profile banners etc. It’s a real pain and waste of time and it only takes away your focus from the actual artwork. At Hike we once decided to invest multiple days into creating a complete Photoshop template that would allow us to create design previews on the fly.

What sets this PSD apart from similar files is the fact that with every update Facebook performs to its fan page design, Hike reproduces it 24 hours later and updates its download link with the latest version. As listed under Features above, we actually reproduced each and every pixel of Facebook’s fan page UI. The PSD includes 4 viewing modes for the most common design tasks and it’s fully vectorized. Thanks to smart grouping and clever labeling, everybody will easily get along in our PSD. If you have suggestions for improving the file or feel like something is still missing, feel free to post it on our Fan Page wall and we will respond. Follow @HikeSocialApps for updates!”

Thank you, guys! We appreciate your work and your good intentions.


© Smashing Editorial for Smashing Magazine, 2011.

 

Any suggestion/comment/feedback is welcome. We offer tech support for any website/design related issues so if you are facing any problem, contact us now. We only charge if we resolve the issue.

Any suggestion/comment/feedback/question is welcome. We offer tech support for any website/design related issues so if you are facing any problem, contact us now. We only charge if we resolve the issue.

I’ve been using LESS religiously ever since I stumbled upon it months ago. CSS was never really a problem for me, in and of itself, but I was intrigued by the idea of using variables to create something along the lines of a color palette for my websites and themes. Having a color palette with a fixed number of options to choose from helps prevent me from going color crazy and deviating from a chosen style.

As it turns out, LESS — and Sass for that matter — are so much more than that. LESS and Sass share a lot of similarities in syntax, including the following:

  • Mixins – Classes for classes.
  • Parametric mixins – Classes to which you can pass parameters, like functions.
  • Nested Rules – Classes within classes, which cut down on repetitive code.
  • Operations – Math within CSS.
  • Color functions – Edit your colors.
  • Namespaces – Groups of styles that can be called by references.
  • Scope – Make local changes to styles.
  • JavaScript evaluation – JavaScript expressions evaluated in CSS.

The main difference between LESS and Sass is the way in which they are processed. LESS is a JavaScript library and is, therefore, processed client-side.

Sass, on the other hand, runs on Ruby and is processed server-side. A lot of developers might not choose LESS because of the additional time needed for the JavaScript engine to process the code and output the modified CSS to the browser. There are a few ways around this. The way I get around it is to use LESS only during the development process. Once I’m finished, I copy and paste the LESS output into a minifier and then into a separate CSS file to be included in place of the LESS files. Another option is to use LESS.app to compile and minify your LESS files. Both options will minimize the footprint of your styles, as well as avoid any problems that might result from the client’s browser not running JavaScript. While this is not likely, it’s always a possibility.

LESS Is More

Installation

Including LESS in something that you’re building is about as easy as it gets:

  1. Go get yourself a copy of less.js;
  2. Create a file to put your styles in, such as style.less;
  3. Add the following code to your HTML’s <head>:
<link rel="stylesheet/less" type="text/css" href="styles.less">
<script src="less.js" type="text/javascript"></script>

Note the rel attribute of the link. You are required to append the /less to the end of the value in order for LESS to work. You are also required to include the script immediately after the link to the style sheet. If you’re using HTML5 syntax, and I can’t imagine why you wouldn’t be, you can leave out the type="text/css" and the type="text/javascript".

There’s also a server-side version of LESS. The easiest way to install LESS on the server is with Node Package Manager (NPM).

Variables

If you’re a developer, variables are one of your best friends. In the event that you’ll be using information repeatedly (in this case, a color), setting it to a variable makes sense. This way, you guarantee yourself consistency and probably less scrolling about looking for a hex value to copy and paste. You can even do some fun little adding and subtracting of hex values that you want to render. Take this example:

@blue: #00c;
@light_blue: @blue + #333;
@dark_blue: @blue - #333;

If we apply these styles to three divs, we can see the gradated effect created by adding and subtracting the hex values to and from the original blue:

A screenshot illustrating the transition from 3 shades of blue

The transition from @light_blue to @blue to @dark_blue.

The only difference in variables between LESS and Sass is that, while LESS uses @, Sass uses $. There are some scope differences as well, which I’ll get to shortly.

Mixins

On occasion, we might create a style that’s intended to be used repeatedly throughout the style sheet. Nothing is stopping you from applying multiple classes to the elements in the HTML, but you could also do this without ever leaving your style sheet, using LESS. To illustrate this, I have pasted some sample code that one might use to style two elements on the page.

.border {
border-top: 1px dotted #333;
}

article.post {
background: #eee;
.border;
}

ul.menu {
background: #ccc;
.border;
}

This will give you something similar to what you would get if you had gone back to the HTML file and added the .bordered class to the two elements there — except you’ve done it without leaving the style sheet. And it works just as well:

A screenshot illustrating two elements that share a border style

Both the article and the unordered list share the border style.

With Sass, you declare @mixin prior to the style to identify it as a mixin. Later, you declare @include to call it.

@mixin border {
border-top: 1px dotted #333;
}

article.post {
background: #eee;
@include border;
}

ul.menu {
background: #ccc;
@include border;
}

Parametric Mixins

Like having functions in your CSS (*swoon*), these can be immensely useful for those seemingly redundant tasks of modern-day CSS. The best and most useful example of their use relates to the many vendor prefixes that we struggle with during this transition from CSS2 to CSS3. Nettuts+ has a wonderful webcast and article by Jeffrey Way, with details on including a file consisting entirely of useful parametric mixins that cover most of your favorite CSS3 properties in the respective vendor prefixes. For example, a simple mixin to handle rounded corners in their various forms:

.border-radius( @radius: 3px ) {
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
border-radius: @radius;
}

In this case, the .border-radius class has a default radius of 3 pixels, but you can pass whatever value you like to get a rounded corner of that radius. Something like .border-radius(10px) will round the corners by 10 pixels.

The syntax in Sass is very similar to that of LESS. Just use the $ for variables, and call the mixins with the @mixin and @include method mentioned earlier.

Selector Inheritance

Here’s something not provided in LESS. With this ability, you can append a selector to a previously established selector without the need to add it in a comma-separated format.

.menu {
	border: 1px solid #ddd;
}

.footer {
	@extend .menu;
}

/* will render like so: */
.menu, .footer {
	border: 1px solid #ddd;
}

Nested Rules

Nesting classes and ids in CSS can be one of the only methods to keep your styles from interfering with and from being interfered with any other styles that may be added along the way. But this can get very messy. Using a selector like #site-body .post .post-header h2 is unappealing and takes up a lot of unnecessary space. With LESS, you can nest ids, classes and elements as you go. Using the example above, you could do something like this:

#site-body { …

    .post { …

        .post-header { …

            h2 { … }

            a { …

            	&:visited { … }
            	&:hover { … }
            }
        }
    }
}

The above code is essentially the same as the ugly selector in the previous paragraph, but it’s much easier to read and understand, and it takes up much less space. You can also refer in element styles to their pseudo-elements by using the &, which in this case functions similar to this in JavaScript.

Operations

This is about what you would expect: using fixed numbers or variables to perform mathematical operations in your styles.

@base_margin: 10px;
@double_margin: @base_margin * 2;

@full_page: 960px;
@half_page: @full_page / 2;
@quarter_page: (@full_page / 2) / 2;

For the record, I am aware that I could have also divided by four to get the @quarter_page variable, but I wanted to illustrate that the parentheses rule from the “order of operations” also applies. Parentheses are also required if you’re going to perform operations within compound properties; for example, border: (@width / 2) solid #000.

Sass is a lot more versatile with numbers than LESS. It has built into it conversion tables to combine comparable units. Sass can work with unrecognized units of measurement and print them out. This feature was apparently introduced in an attempt to future-proof the library against changes made by the W3C.

/* Sass */
2in + 3cm + 2pc = 3.514in

/* LESS */
2in + 3cm + 2pc = Error

Color Functions

Earlier, I mentioned how LESS helps me stick to a color scheme in my coding process. One of the parts that contributes to this the most is the color function. Suppose you use a standard blue throughout your styles, and you want to use this color for a gradated “Submit” button in a form. You could go into Photoshop or another editor to get the hex value for a slightly lighter or darker shade than the blue for the gradient. Or you could just use a color function in LESS.

@blue: #369;

.submit {
    padding: 5px 10px;
    border: 1px solid @blue;
    background: -moz-linear-gradient(top, lighten(@blue, 10%), @blue 100%); /*Moz*/
    background: -webkit-gradient(linear, center top, center bottom, from(lighten(@blue, 10%)), color-stop(100%, @blue)); /*Webkit*/
    background: -o-linear-gradient(top, lighten(@blue, 10%) 0%, @blue 100%); /*Opera*/
    background: -ms-linear-gradient(top, lighten(@blue, 10%) 0%, @blue 100%); /*IE 10+*/
    background: linear-gradient(top, lighten(@blue, 10%) 0%, @blue 100%); /*W3C*/
    color: #fff;
    text-shadow: 0 -1px 1px rgba(0,0,0,0.4);
}

The lighten function literally lightens the color by a percentage value. In this case, it will lighten the base blue by 10%. This method enables us to change the color of gradated elements and any other elements with that color simply by changing the base color itself. This could prove immensely helpful in theming. Plus, if you used a parametric function, like the ones listed above, you could alleviate some of that browser-prefix tedium with something as simple as .linear-gradient(lighten(@blue), @blue, 100%);.

Either way, you get an effect that’s rather nice:

Screenshot of a styled submit button

Our nicely gradated, variable-based “Submit” button.

There are a lot of other color functions for darkening and saturating colors and even spinning the color wheel to other colors. I recommend trying them out to see what you can come up with.

Sass seems to have a lot more color options — not that I would need them all. Lighten and darken are the only ones that I see myself using often. For more detail, Nex3 has an in-depth article on the topic.

Conditionals and Control

This is rather nifty, and another thing not provided by LESS. With Sass, you have the ability to use if { } else { } conditional statements, as well as for { } loops. It supports and, or and not, as well as the <, >, <=, >= and == operators.

/* Sample Sass "if" statement */
@if lightness($color) > 30% {
  background-color: #000;
} @else {
  background-color: #fff;
}

/* Sample Sass "for" loop */
@for $i from 1px to 10px {
  .border-#{i} {
    border: $i solid blue;
  }
}

Namespaces

Namespaces can be used to add another level of organization to our CSS, by allowing us to create groups of commonly used styles and then pick from them along the way. For instance, if we created a group of styles called defaults, we could pull from this group when we come across an element that needs it.

#defaults {
	.nav_list () {
		list-style: none;
		margin: 0; padding: 0;
	}
	.button () { … }
	.quote () { … }
}

Later, in our code, if we come across a ul element within a nav element, we would know that we’ll need our default style. So, we can simply call it, and it will be applied.

nav ul {
	#defaults > .nav_list;
}

Scope

Scoping is standard throughout programming and thus standard in LESS. If you define a variable at the root level of your style sheet, it will be available and consistent throughout the document. If, however, you redefine the variable from within a selector such as an id or class, then it will be available — with the new value — only within that selector.

@color: #00c; /* blue */

#header {
	@color: #c00; /* red */

	border: 1px solid @color; /* will have a red border */
}

#footer {
	border: 1px solid @color; /* will have a blue border */
}

Because we’ve restated the variable within the #header selector, the value for that variable will be different and will apply only within that selector. Anything before or after it will retain the value of the original statement.

Scope is handled a little differently in Sass. In the above code, when the @color variable is changed to red, it will be interpreted as such from that point on within the code.

Comments

This part is pretty basic. Two types of comments are valid in LESS. The standard CSS comment, /* comment */, is valid and will get passed through the processing and outputted. Single-line comments, // comment, work as well but will not get passed and outputted and, as a result, are “silent.”

Importing

Importing is pretty standard, too. The standard @import: 'classes.less'; works just fine. If, however, you’re importing another LESS file, then the file extension is optional, so @import 'classes'; would work as well. If you want to import something without LESS processing it, you can use the .css extension (for example, @import: 'reset.css';).

String Interpolation

String values can also be used in variables and called within styles via @{name}.

@base_url = 'http://coding.smashingmagazine.com';
background-image: url("@{base_url}/images/background.png");

Escaping

There will be times when you need to include a value that is not valid CSS syntax or that LESS doesn’t recognize. More often than not, it will be some crazy Microsoft hack. To avoid throwing errors and breaking LESS, you will need to escape them.

.class {
	filter: ~"progid:DXImageTransform.Microsoft.Alpha(opacity=20)";
}

/* Will actually be outputted like this: */
.class {
	filter: progid:DXImageTransform.Microsoft.Alpha(opacity=20);
}

JavaScript Evaluation

This is one of my favorite parts of LESS: using Javascript in style sheets — simply brilliant. You can use expressions and also reference aspects of the environment using backticks.

@string: `'howdy'.toUpperCase()`; /* @string becomes 'HOWDY' */

/* You can also use the previously mentioned interpolation: */
@string: 'howdy';
@var: ~`'@{string}'.topUpperCase()`; /* becomes 'HOWDY' */

/* Here we access part of the document */
@height = `document.body.clientHeight`;

Output Formatting

Whereas LESS has no output settings, Sass provides four output versions: nested, compact, compressed and expanded.

Final Thoughts

These two libraries share a lot of basics. Both of them are fantastic tools for designers who code, and they can also help developers work more efficiently and quickly. If you’re a fan of Ruby or HAML, then Sass might be right up your ally. For me, being a PHP and JavaScript geek, I tend to lean towards LESS for its ease of inclusion and access to JavaScript’s expressions and document attributes. I doubt that I’ve even come close to truly grasping the possibilities of programming in my style sheets, but I am intent on trying. If you’ve been using either, or both, of these in your work, I’d love to hear more about it and see some of your results. Tips, tricks and corrections are, of course, always welcome as well.

(al)


© Jeremy Hixon for Smashing Magazine, 2011.

Any suggestion/comment/feedback is welcome. We offer tech support for any website/design related issues so if you are facing any problem, contact us now. We only charge if we resolve the issue.


Follow Us!

Search

Post requirement / Ask for Support!

Do you have question related to website designing, graphic designing or need any technical support, feel free to contact us. Contact us at mail@topwebsitedesigning.com or call +91-9582929295. You can also skype me on "s.goel1"
Contact +91-9582929295

ad