Showing posts with label CSS. Show all posts
Showing posts with label CSS. Show all posts

Wednesday, July 7, 2010

20 Excellent Examples of CSS

With the launch of the iPhone 4 and the general increase in mobile web use (aka the iPhone, iPod touch and iPad), the value of animations done using the all new CSS3 or Cascading Style Sheet 3, has risen dramatically.

Throw in the fact that Adobe Flash is a forbidden fruit in the world of iDevices, CSS and JQuery powered animations are going to rule the next generation of rich internet media. CSS3 allows designers to write light weight animations that can be easily embedded into web pages and best of all they don't have to bind it with any license like with Flash which is a protected commercial platform.

We have handpicked our top 20 examples of great animations created using CSS3 and JavaScript. Some of these demos contain downloadable source files too so that you may play with them later on.

NOTE: CSS3 animations require a WebKit engine based browser which means you can only view them on Google Chrome or Apple Safari. Although some of them work on Firefox , most don't.

1. Image Gallery based on CSS3 Transitions

You won't believe it but this image gallery has been completely designed using CSS and JQuery calls. CSS3 transitions have been used to create the event listeners. Chrome & Safari are fully supported but it also works fine on Firefox.

2. 3D Object Rotation Using Arrow Keys

Again, there is absolutely no Flash involved here. The coke can rotates as you scroll the bar to the right and the can looks like it's a 3D object. CSS Displacement maps were used to create the illusion of 3D object movement.

3. 3D Object Rotation Using Arrow Keys

This sample gallery titled "Land of Nomads" is yet another beautiful example of a purely CSS based interactive Image gallery. You can click any image from the pack of jumbled images and it would be enlarged and moved to top left corner of your screen to make it prominent. See the speed of it's load time since there is no Flash involved here.

4. Three Dimensional Space Simulation

Now this example is simply awesome. It's not just images or animations, it's complete space simulated in 3D right in your browser. You can only view it on Chrome and Safari. Probably there are multiple layers of images that give 3D effect when combined and rotated on their own axes. It's all the play of writing a "spinner" in CSS and then timing it to make it 3D.

5. Rotating Color Band Timer

A perfect example that you can enlarge and make your wall-paper. The 3 color bands that revolve around the Hour, Minute and Seconds ticks are simply amazing. You cannot spot any delay in the movement of the bands as is usually the case with Flash. There is a bit of XHTML involved and you can also download the Clock simulation CSS files from here.

6. Elastic Thumbnail Menu

This will work great for any online product display website or website that has thumbnails spread over their pages. CSS has been used to animate the thumbnails so that when you hover over them, they are enlarged to make them prominent and also give an overall cool look. Definitely recommended for Shopping websites.

7. iTunes Like Slider in CSS

This animated icon tray runs really smooth in both Chrome and Safari and resembles the much acclaimed iTunes Icons Slider. You can move the icons right and left with the slider or with left and right keys. JQuery UI is used to give it the sleek look.

8. Animated DJ Discs

CSS is used in clever combination with JQuery to create this visual DJ that can be controlled with a mouse. You can actually rotate the discs with mouse and the sound pitch changes accordingly. Again, JQuery UI was employed to create the rotation motion effect.

9. Dynamic Index Card Stacks

This looks similar to the Image galleries we have reviewed so far but it's not. The difference is in the way the cards come to the foreground and do not move around the screen. Previously these animations would have been written using the Adobe Flash platform but now the light weight CSS+JS has taken it's spot. A cool application for this card stack would be using them in an online book reader. You can read the tutorial on how to make this animated card stack here.

10. Fixed Motion Animated Image Gallery

This is yet another Image Gallery created using pure CSS (not even JS). Images are jumbled up with their captions at the bottom right of the images. The hover over effect has been added so that the images rotate and align themselves when the cursor moves over one of the images.

11. Vertical Button Menus

Usually JS is used in creating dynamic animated button menus for websites but with pure CSS3 that is now possible without any JS at all. The proof is this demo showing vertical menu bars with different number of button ordered vertically and which respond to hover-over event of the mouse. This demo is by Toby Pitman, an acclaimed CSS/web designer.

12. Docking Menu

This menu is designed and written using SVG and CSS3 Transition (a previous review used Transitions to create animated Image gallery). Just like the Stack of Cards example, here the menu items respond to the hover-over event they are enlarged and brought forward when you move your cursor over them. The total programming that goes behind this animated menu is not more then one page and creates this stunning user friendly menu!

13. Movable Sticky Notes

This is simply awesome. You wouldn't recognize that CSS is used in creating these animated sticky notes. You can create new notes on the browser page, edit them with full text alignment support, move them around and then delete them right from within the browser without any Flash involved. HTML5 Client side Data storage concepts are used to hold the data written on the notes. This is true UI in action!

14. Snowball Effect

You might have seen this snowfall effect before where it was written in JS , but here they've used CSS3 Sliders to write the snowfall effect. It may be Summer heat out but this snowfall effect can add a cool feeling to your pages without taking any extra processing as is the case with Flash whose FLV decoder puts a lot of load on the CPU.

15. Cartoon Animation

Now we also have animated cartoons, not just animated images done completely in CSS. This demo by CSSPlay UK definitely shows the potential of creating rich content on the internet using CSS and JS. You have to keep the mouse moving over the frame to keep the animation running. In the Firefox version, you have to keep clicking your mouse to keep the animation running. A smart use of CSS Selectors made this happen.

16. Dynamic Animated Content Gallery

Something that was previously done using the Adobe Flash dynamic-button event handlers is now completed done using JQuery UI with CSS3 and what you have is a complete dynamic content gallery. In this demo, a matrix of thumbnail sized images are on display and each image responds to the hover-over event and a card is created next to the cursor with the information of that image. Everything is handled dynamically with out any delay at all. The images are of presidents of countries around the globe. You will have to click download on the page to proceed to this animated gallery.

17. Tab Slider

This is an impressive example from CSS Ninja where tabs containing a title bar with some content in plain text are arranged in close order. They expand upon clicking them and contract again when another tab is clicked. The content is static but the animations are done in real time. The accordion effect of CSS3 is used here to create this animated tabbed text. You can download the source files for this demo from here.

18. Completely Animated AT-AT Walker

The capability of animating multiple objects in a frame simultaneously in CSS3 has been demonstrated here with the robot AT-AT made up of many components and each one is moving in it's own defined course at the same time. This gives an illusion of an object moving around in the frame. Even the background is changing according to the movement of AT-AT.

19. JQuery+CSS Sleek Menu

This is by far the best sliding button menu that CSS has to offer. Not only is it animated like the images in the CSS based gallery, but the thumbnail sized buttons change their color while in inactive mode. A button becomes visible with all its colors when you hover over it. A transparent layer is spread over non-active buttons while the cursor is on one of the buttons. The designer claims that Flash will be obsolete when animation this rich can be written using open standards of CSS3 and JQuery.

20. Dynamically Expanding and Movable Image Gallery

Yet another CSS based Image gallery but a lot different from the ones reviewed in the above examples. You can completely move around in the gallery with arrow keys. The gallery slides smoothly when moved and the images also are expanded upon hovering over them. Another proof-of-concept of what CSS3 could achieve.

Monday, July 5, 2010

25 Incredibly Useful CSS Tricks You Should Know

Here are 25 incredibly useful CSS tricks that will help you design great web interfaces. You might be aware of some or all of these techniques, but this can be your handy resource to nifty CSS tricks that you should know.

1. CHANGE TEXT HIGHLIGHT COLOR

You might not have known this before! With CSS you can control the colors of selected test at least for standards compliant cutting edge browsers like Safari or Firefox.
  1. ::selection{ /* Safari and Opera */
  2. background:#c3effd;
  3. color:#000;
  4. }
  5. ::-moz-selection{ /* Firefox */
  6. background:#c3effd;
  7. color:#000;
  8. }

2. PREVENT FIREFOX SCROLLBAR JUMP

Firefox usually hides the vertical scrollbar if size of the content is less than the visible window but you can fix that using this simple CSS trick.
  1. html{ overflow-y:scroll; }

3. PRINT PAGE BREAKS

While most of the internet users prefer to read content online but some of your users might like to print your article. With CSS you can control the page breaks within content just add this CSS class to your stylesheet and add this class to any tag which you would like to print on next page.
  1. .page-break{ page-break-before:always; }

4. USING !IMPORTANT

Experienced CSS programmers are usually aware of this but beginners do miss out on this !important CSS rule. By adding !important to your CSS rule, you can increase its precedence over other subsequent rules. e.g. in below code, background-color will be blue and not red due to !important.
  1. .page { background-color:blue !important; background-color:red;}

5. REPLACE TEXT WITH IMAGE

This is a nice SEO trick that lets you show a nice fancy image instead of simple boring text to your visitors but search engines will see only the text.
  1. .header{
  2. text-indent:-9999px;
  3. background:url('someimage.jpg') no-repeat;
  4. height: 100px; /*dimensions equal to image size*/
  5. width:500px;
  6. }

6. CROSS BROWSER MINIMUM HEIGHT

Internet Explorer does not understand the min-height property but here’s the CSS trick to accomplish that in IE.
view plaincopy to clipboardprint?
  1. #container{
  2. height:auto !important;/*all browsers except ie6 will respect the !important flag*/
  3. min-height:500px;
  4. height:500px;/*Should have the same value as the min height above*/
  5. }

7. HIGHLIGHT LINKS THAT OPEN IN A NEW WINDOW

This piece of CSS code will highlight links that open in a new window so that user knows before hand that link will pop open in a new tab or window.
  1. a[target="_blank"]:before,
  2. a[target="new"]:before {
  3. margin:0 5px 0 0;
  4. padding:1px;
  5. outline:1px solid #333;
  6. color:#333;
  7. background:#ff9;
  8. font:12px "Zapf Dingbats";
  9. content: "\279C";
  10. }

8. STYLE YOUR ORDERED LIST

Style Ordered List
Style numbers of an ordered list in different way than the content of each list item.
  1. ol {
  2. font: italic 1em Georgia, Times, serif;
  3. color: #999999;
  4. }
  5. ol p {
  6. font: normal .8em Arial, Helvetica, sans-serif;
  7. color: #000000;
  8. }

9. DROP CAPS USING CSS

Drop Caps using CSS
You can create a drop caps effect like those in newspapers or magazines using the :first-letter pseudo element.
  1. p:first-letter{
  2. display:block;
  3. margin:5px 0 0 5px;
  4. float:left;
  5. color:#FF3366;
  6. font-size:3.0em;
  7. font-family:Georgia;
  8. }

10. CROSS BROWSER OPACITY

Though CSS3 standard includes the opacity property, but not every browser supports it, here’s the CSS trick for cross browser transparency.
  1. .transparent_class {
  2. filter:alpha(opacity=50);
  3. -moz-opacity:0.5;
  4. -khtml-opacity: 0.5;
  5. opacity: 0.5;
  6. }

11. VERTICAL CENTERING WITH LINE-HEIGHT

If you are using fixed height container and need to vertically center the text, use the line-height property to do that perfectly.
  1. line-height:30px;

12. CENTER FIXED WIDTH LAYOUT

If you use fixed width layout, you should center the layout so that if somebody views it on larger screen, the page displays in the center of the screen and not on left side.
  1. body{
  2. width:1000px;
  3. margin:0 auto;
  4. }

13. REMOVE VERTICAL TEXTAREA SCROLLBAR IN IE

IE adds a vertical scrollbar to textarea input fields regardless of the height of content in it. You can fix that with this simple CSS trick.
  1. textarea{
  2. overflow:auto;
  3. }

14. REMOVE ACTIVE LINK BORDERS

Some browsers like Firefox and IE add a dotted outline border over the link user clicked. It is a useful accessibility feature that lets user know which link he clicked or is in focus. But sometimes you need to get rid of this, here’s the CSS you need to use.
  1. a:active, a:focus{ outline:none; }

15. PREVENT ELEMENTS FROM DISAPPEARING IN IE

Sometimes IE behaves in a peculiar way and makes some elements disappear, which appear when you try to make a selection. It is due to some IE issues with float elements. This can be fixed by adding position:relative; to elements that disappears.

16. ATTRIBUTE-SPECIFIC ICONS

CSS Attribute selectors are very powerful giving you many options to control styles of different elements e.g. you can add an icon based on the href attribute of the a tag to let the user know whether link points to an image, pdf, doc file etc.
  1. a[href$='.doc'] {
  2. padding:0 20px 0 0;
  3. background:transparent url(/graphics/icons/doc.gif) no-repeat center right;
  4. }

17. CSS POINTER CURSORS

This trend has caught up lately. All user interface elements on a web page that can be clicked by user have their cursor similar to that of hyperlink. Here’s the CSS trick to do that.
  1. input[type=submit],label,select,.pointer { cursor:pointer; }

18. CAPITALIZE TEXT

This trick is especially useful for displaying title of an article on a web page with all its words starting with capital letter.
  1. text-transform: capitalize;

19. SMALL CAPS TEXT

This is one of the lesser used but useful CSS property. It capitalizes all the letters of text but the size of letters following the first letter of each word is smaller than the first letter.
  1. font-variant:small-caps;

20. HIGHLIGHT TEXT INPUT FIELDS

This CSS trick lets you highlight the input field currently in focus. This trick does not work in IE though.
  1. input[type=text]:focus, input[type=password]:focus{
  2. border:2px solid #000;
  3. }

21. REMOVE IMAGE BORDER

Image hyperlinks usually get a ugly blue border that makes your image hyperlinks look horrible. It’s better to remove border on all hyperlinked images and add individually to those you want using CSS classes.
  1. a img{ border:none; }

22. TABLELESS FORMS USING LABELS

Tableless Forms using labels and CSS
Gone are the days when tables were used to layout Forms. CSS lets you make accessible forms with table like layout using label tags. Using label tags makes sure your forms are more accessible. Here’s sample html and css code for tableless form using labels.
  1. "#" method="post">
  2. "username" name="username" type="text">
  3. ="password">Username
  4. "password" name="pass" type="password">
  5. "submit" value="Submit">
  1. p label{
  2. width:100px;
  3. float:left;
  4. margin-right:10px;
  5. text-align:right;
  6. }

23. SET A CONSISTENT BASE FONT SIZE

Setting the font-size property to 62.5% in body tag makes 1em equal to 10px. This lets you use em easily as you can find out the font-size in pixels from em values.
  1. body{ font-size:62.5%; }

24. HIGHLIGHT ACRONYM AND ABBR TAGS

acronym and abbr tags provide useful information to users, browsers and search engines about acronyms and abbreviations, but most of the browsers except Firefox do not highlight them. Here’s the CSS trick to highlight acronym and abbr tags within your web page.
  1. acronym, abbr{
  2. border-bottom:1px dotted #333;
  3. cursor:help;
  4. }

25. CSS RESET BY ERIC MEYER

This piece of CSS code resets all the browser default styles preventing any browser inconsistencies in your CSS styles.
  1. html, body, div, span, applet, object, iframe,
  2. h1, h2, h3, h4, h5, h6, p, blockquote, pre,
  3. a, abbr, acronym, address, big, cite, code,
  4. del, dfn, em, font, img, ins, kbd, q, s, samp,
  5. small, strike, strong, sub, sup, tt, var,
  6. b, u, i, center,
  7. dl, dt, dd, ol, ul, li,
  8. fieldset, form, label, legend,
  9. table, caption, tbody, tfoot, thead, tr, th, td {
  10. margin: 0;
  11. padding: 0;
  12. border: 0;
  13. outline: 0;
  14. font-size: 100%;
  15. vertical-align: baseline;
  16. background: transparent;
  17. }
  18. body {
  19. line-height: 1;
  20. }
  21. ol, ul {
  22. list-style: none;
  23. }
  24. blockquote, q {
  25. quotes: none;
  26. }
  27. blockquote:before, blockquote:after,
  28. q:before, q:after {
  29. content: '';
  30. content: none;
  31. }
  32. /* remember to define focus styles! */
  33. :focus {
  34. outline: 0;
  35. }
  36. /* remember to highlight inserts somehow! */
  37. ins {
  38. text-decoration: none;
  39. }
  40. del {
  41. text-decoration: line-through;
  42. }
  43. /* tables still need 'cellspacing="0"' in the markup */
  44. table {
  45. border-collapse: collapse;
  46. border-spacing: 0;
  47. }