50 Useful Coding Techniques (CSS Layouts, Visual Effects and Forms)

Advertisement

Although CSS is generally considered a simple and straightforward language, sometimes it requires creativity, skill and a bit of experimentation. The good news is that designers and developers worldwide often face similar problems and choose to share their insights and workarounds with the wider community.

This is where we come in. We are always looking to collect such articles for our posts so that we can deliver the most useful and relevant content to our readers. In this post, we present an overview of useful CSS/jQuery coding tips, tricks and techniques for visual effects, layouts and web form design to help you find solutions to the problems you are dealing with or will have to deal with in future.

You may want to look at similar CSS-related posts that we published last months:

CSS Layouts: Techniques And Workarounds

Facebook Style Footer Admin Panel4
Learn how to re-create the Facebook footer admin panel with CSS and jQuery. Also check out part 25.

Facebook Style Footer Admin Panel6

Adaptable View: How Do They Do It?7
This tutorial explains how to manually change a layout, and it shows two great examples and “how they did it.”

Adaptable view - how do they do it?8

Easy Display Switch with CSS and jQuery9
A quick and simple way to enable users to switch page layouts using CSS and jQuery.

  Easy Display Switch with CSS and jQuery10

Quick Tip – Resizing Images Based On Browser Window Size11
In fluid layouts, formatting text to adjust smoothly to window size is easy, but images are not as fluid-friendly. This quick tip shows how to switch between two image sizes based on the size of the browser, the DIV or whatever else you choose.

Quick Tip - Resizing Images Based On Browser Window Size12

One Page Résumé Site13
A clean layout on one page—literally (just one index.html file with optional images). It comes with contact information in microformats and a main area for the resume using a definition list (dl). And it prints well.

One Page Résumé Site14

Pegs: Automate Display: fixed++15
Chris Wetherell posts on Pegs, a strategy for having one scroll bar but independent scrolling areas. After the first one, click on the other items to flip between sizes. You will see that an area’s scroll depends on the configuration.

Pegs: Automate display: fixed++16

CSS 100% Height17
A common problem among designers is how to get a div to stretch 100% of the window’s height. There are a few different techniques out there, and this tutorial shows one of them.

CSS 100% Height18

CSS3 Drop-Down Menu19
A clean, simple a nice navigation menu, designed by Nick La.

Fluid Images20

CSS Trick for a Scrolling Transparent Background Effect21
Scroll the page to watch a battle between good and evil take shape. The effect requires two images: one transparent and one tiled gradient image. The gradient scrolls under the transparent PNG. Because it matches the colors in the PNG, each set of images disappears, depending on the part of the gradient they’re on top of.

CSS Trick For A Scrolling Transparent Background Effect22

Fluid Images23
By default, an image element that is 500 pixels doesn’t exactly play nice with a container as large as 800 pixels or one as small as 100. What’s a designer to do?

Fluid Images24

Scroll/Follow Sidebar, Multiple Techniques25
A really simple concept: the sidebar follows you as you scroll down the page. There are a number of ways to go about it. Two are covered here: CSS and JavaScript (jQuery), with a bonus CSS trick.

Scroll/Follow Sidebar, Multiple Techniques26

Vertical Centering With CSS27
There are a few different ways to vertically center objects using CSS, but choosing the right one can be difficult. Here is a list of the best ways and an explanation of how to create a nice centered website.

 Vertical Centering With CSS28

Create YouTube-like adaptable view using CSS and jQuery29
Other than the “Turn off the lights” feature, YouTube has great stuff, such as the “change view” feature, which allows you to switch between normal and wide mode, thus expanding or shrinking the video area. Creating this is very simple.

Create YouTube-like adaptable view using CSS and jQuery30

How To Create a Horizontally Scrolling Site31
If websites were made of wood, the grain would run up and down. Vertical is the natural flow of the Web. But browsers are equipped with vertical and horizontal scroll bars, right? We have the choice to go against the grain and create web pages that scroll primarily horizontally and that even expand horizontally to accommodate more content. Perhaps a slight blow to usability, but a cool creative touch nonetheless!

How To Create a Horizontally Scrolling Site 32

Purely CSS – Faking Minimum Margins33
min-margin is non-existent in the CSS world. After you’ve pondered and Googled it, check out the solution here.

Purely CSS - Faking Minimum Margins 34

Create Sidebars of Equal Height with Faux Columns35
CSS can be tricky business. Creating columns of equal height, where the content in one column is longer than the content in another, is frustrating. Here’s where the faux-column technique can help. Find out how this solution makes even the most complicated layout a breeze to code.

Setting Equal Heights with jQuery36
Here is a script to match the heights of boxes in the same container and create a tidy grid, with little overhead.

Setting Equal Heights with jQuery37

Quick Tip: Centered Fake Floats38
There were ways to center-align left-floated elements, but then inline-block became popular and everything changed. After a bit of tinkering, Zaharenia Atzitzikaki found an efficient and (mostly) cross-browser-compatible way to center elements without floats.

6 Flexible jQuery Plugins to Control Web Page Layouts Easily39
A collection of six jQuery plug-ins to manage page layouts easily.

  6 Flexible jQuery Plugins To Control Webpage Layouts Easily40

Four Methods to Create Equal-Height Columns41
This article discusses ways to create equal-height columns that work in all major browsers (including IE6). All of the methods show how to create a three-column layout.

Four Methods to Create Equal Height Columns 42

How to: CSS Large Background43
A tutorial with various CSS examples for how to create a large background using either a single image or double images.

  How to: CSS Large Background44

A Nice Little CSS Positioning Technique45
Here, we have a basic unordered list (ul), with left-floated images where the text doesn’t wrap under the images. Of course, this technique could be deployed in loads of other instances.

A Nice Little CSS Positioning Technique 46

Perfect Full Page Background Image47
This technique allows an image to fill the page, with no white space. The image scales as needed and retains its proportions, without triggering scroll bars.

Perfect Full Page Background Image 48

Smart Columns With CSS and jQuery49
In observing liquid-width websites, Soh Tanaka sees two common techniques for displaying columns: fixed columns and liquid columns. He points out the drawbacks of both and pitches his solution.

Smart Columns w/ CSS and jQuery50

Images And Visual Effects With CSS

A Beautiful Apple-Style Slideshow Gallery With CSS and jQuery51
Create an Apple-like slideshow gallery, similar to the one used on Apple’s website to showcase products. It works entirely in the front end; no PHP or databases required.

A Beautiful Apple-style Slideshow Gallery With CSS and jQuery 52

Rolling a coke can around with pure CSS53
Román Cortés is having a lot of fun doing CSS tricks these days. He just built a rolling coke can that uses background-attachment, background-position and a few other tricks to achieve the effect. No fancy CSS3 needed here!

 Rolling a coke can around with pure CSS54

Grayscale Hover Effect With CSS and jQuery55
A few months ago, James Padolsey introduced a cool grayscale technique for non-IE browsers. His technique inspired Soh Tanaka to come up with a workaround with a similar effect. His solution relies on CSS Sprites and a few lines of jQuery, but it requires a bit of preparation before implementation. It is not recommended for large-scale projects; it is probably best for portfolio pieces.

Greyscale Hover Effect w/ CSS and jQuery56

Codename Rainbows57
Some JavaScript and CSS magic is used here to apply a two-color gradient to text. Shadows and highlights can also be applied. This works especially well on big websites and for dynamic content where creating images for every instance would be impractical.

 Codename Rainbows58

3 Easy and Fast CSS Techniques for Faux Image Cropping59
This article summarizes three fast and easy CSS techniques for displaying only a portion of an image. All of the techniques need only a couple of lines of CSS. You are not literally cropping, which is why it’s called faux image cropping. These techniques can be helpful if you want to keep images to a certain size (for example, thumbnails in a news section). Being able to use CSS to control which portion of an image to display is great.

3 Easy and Fast CSS Techniques for Faux Image Cropping60

Image Rollover Borders That Do Not Change Layout61
With CSS, the border of any block-level element is factored into the element’s size in the layout. So, if you add a border to an element on hover, the layout will shift. In this post, you will find how to use the regular border property and create inner borders to get around that.

Image Rollover Borders That Do Not Change Layout 62

Horizontal Stripes63
This tutorial shows you how to create never ending horizontal stripes in your web design using CSS.

Horizontal Stripes64

Nine Techniques for CSS Image Replacement65
Put nine different techniques of image replacement to the test.

Nine Techniques for CSS Image Replacement66

Bokeh effects with CSS3 and jQuery67
This tutorial teaches you how to re-create the bokeh effect with CSS 3. With some help from jQuery, we can add some randomness in colour, size and position for the effect.

Bokeh effects with CSS3 and jQuery68

A Stationary Logo That Changes on Page Scroll with CSS 69
Here is an interesting effect that modifies the logo when the page is scrolled, using the CSS background-attachment property.

A Stationary Logo That Changes on Page Scroll with CSS 70

Silhouette Fade-Ins71
To achieve the effect in the image above, first we need a DIV with the silhouettes as a background image. Then we put four images in that DIV, all the exact same size, with each band member highlighted. These images are hidden by default. Then you absolutely position four regions on top of the DIV; these are the roll-over link areas. With jQuery, we apply hover events to them, fading in the appropriate image.

Silhouette Fadeins72

Creating Triangles in CSS (the link was removed due to possible malware)
Few people realize that a browser draws borders at angles. This technique takes advantage of that. One side of the border is given the color of the arrow, and the rest are transparent. Then you give the border a large width; the ones above are 20 pixels.

Creating Triangles in CSS  73

A parallax optical illusion with CSS: The Horse in Motion74
Time for some fun with CSS and optical illusions.

A parallax optical illusion with CSS: The Horse in Motion75

Pure CSS Line Graph76
The idea here is not only to offer data visualization to people who aren’t comfortable using scripting languages, but to demonstrate the power of CSS and offer a different way of using CSS. If you are not a fan of line graphs and data visualization, you may still benefit from this article. Think of it as a CSS experiment, and learn a thing or two about CSS Sprites and positioning.

Pure Css Line Graph 77

Zooming with jQuery and CSS78
This post is about text zooming with jQuery and CSS. This is a basic-level tutorial about changing a style using a jQuery script. A simple way to zoom website content.

Zooming with jQuery and CSS79

Create Resizing Thumbnails Using Overflow Property80
This tutorial teaches you how to control thumbnail sizes. Sometimes we don’t have enough space to fit large thumbnails, and yet we would rather avoid small indecipherable images. Using this trick, we can limit the default dimensions of thumbnails and show them at full size when the user mouses over them.

Create Resizing Thumbnails Using Overflow Property 81

Cross-browser drop shadows using pure CSS82
Most methods of adding drop-shadows to content blocks require additional HTML mark-up and one or more PNG images. But by combining the Glow and Shadow filters, something that fairly closely resembles the rendered CSS3 shadow can be achieved.

Cross-browser drop shadows using pure CSS 83

Date Badges and Comment Bubbles for Your Blog84
One of the things you have to deal with when your blog grows is having to cram more info into less space to show everything you want to show. One thing you can do is add an icon for the date and then a bubble over it with the number of comments for that post.

Date Badges and Comment Bubbles for Your Blog85

CSS Tables And Web Forms

UX trick: display form data as tabular data86
This is a little trick to enhance the user experience of forms. It displays editable form data as readable tabular data.

UX trick: display form data as tabular data87

Tables: Not As Evil As You Think88
Tables are evil, right? Yes and no. For tabular data, they’re not, of course. That’s what tables are for in the first place. CSS can do an excellent job of styling a properly formatted table, and the table structure provides good scaffolding for JavaScript calls. But what is addressed here is using tables for non-tabular data (i.e. for the layout). Yes, that’s right: using tables for layout.

 Tables: Not As Evil As You Think89

Perfect Drop-Down Log-In Box Like Twitter Using jQuery90
This shows you how to create a Twitter-style drop-down log-in form using jQuery. It’s really easy, it saves space on the page and visitors feel comfortable with the awesome toggle form.

Perfect Dropdown Login Box like Twitter using jQuery91

Make a Select’s Options Printable92
When printing a Web page with select elements on it, the select drop-down prints just as it looks on the Web. This of course is practically useless on the printed page. One option for handling this is to follow every select HTML element with an unordered list that duplicates the content. Hide the unordered list in your main CSS file and reveal it with your print style sheet. This is a reasonable approach, except that it’s a big ol’ pain in the butt to deal with all the time. Let’s rely on jQuery to do the heavy lifting instead.

Make a Select's Options Printable93

Twitter-Like Log-In With jQuery and CSS94
This post explains how to get the Twitter-like hide and show effect for logging in using jQuery and CSS.” Very simple: just five lines of JavaScript for the hide() and show() events and a little CSS.

Twitter like Login with Jquery and CSS95

Clean and Pure CSS Form Design96
This tutorial illustrates how to design a pure CSS form without using HTML tables.

 Clean and pure CSS FORM design97

CSSG Collection: Free Comment Styles98
This is the second CSSG collection from CSS Globe.

CSSG Collection: Free Comment Styles 99

Have a Field Day with HTML5 Forms100
Here is a look at how to style a beautiful HTML5 form using some advanced CSS and the latest CSS3 techniques. You will definitely want to re-style your forms after having read this article.

24 ways: Have a Field Day with HTML5 Forms101

Editable/Printable Invoice102
Create editable and printable invoices using CSS and some JavaScript. This is version 2 from Vinh Pham.

Editable/Printable Invoice, Version 2 103

How to Mask Passwords Like the iPhone104
Many smartphones, including the iPhone, show the last character that you typed in a password field with a delay of a second or two. You can see that last character but not the entire password. But browsers don’t do what these mobile devices do. Here is a solution, with some fancy JavaScript and behind-the-scenes trickery.

How to Mask Passwords Like the iPhone105

Make Web Forms Suck Less With Labels106
We’ve been filling out Web forms for years, and we all gripe that they could be better. Even with generous padding, the fields are too small. But hardly anyone has improved the most under-rated interaction of them all: checkboxes and radio buttons.

 Make Web Forms Suck Less With Labels107

FancyForm: JavaScript checkbox replacement108
FancyForm is a powerful and flexible checkbox-replacement script that changes the appearance and function of HTML form elements. It is accessible and easy to use, and it degrades gracefully on older non-supported browsers.

FancyForm - Javascript checkbox replacement109

jQuery checkbox v.1.3.0 Beta 1110
A lightweight custom-styled checkbox implementation for jQuery 1.2.x and 1.3.x.

jQuery checkbox v.1.3.0 Beta 1111

Disabled labels and the Trilemma plug-in112
The form above on the left makes use of the disabled attribute, but the default browser settings for disabled inputs don’t contrast as much as one would like. To better distinguish at a glance between which inputs are disabled and enabled, the labels of disabled inputs in the form on the right are styled with a faint gray color.

Disabled labels and the Trilemma plugin 113

Fluid Search Box114
Creating a fluid search box when you have only a single element next to it is trivial. What you should do is wrap the input in an element and use padding to create space for the fixed element; then position the fixed element absolutely (or relatively) in the space created by the padding.

Last Click

Browser Pong115
A whole new pong game using three browser windows for the ball and racquets. Clever!

Browser Pong116

(kk) (jb) (vf) (al)

↑ Back to topShare on Twitter

The Smashing team loves high-quality content and cares about the little details. Through our online articles, books and eBooks and Smashing Conferences, we are committed to stimulating creativity and strengthening the web design community’s creative forces.

  1. 1

    First! Really nice article, gonna bookmark this one for sure! Tnx SM :-)

    1
  2. 2

    we…e..e…this is awesome collection technique
    hoosshhh!!!

    1
  3. 3

    Nice article and really useful.
    Thank you Smashing. ;-)

    1
  4. 4

    very nice collection… i would also interested to know the slider order form is done, where you add things and its calculated in bottom…

    0
  5. 5

    Smashing Compilation !!! This will come in handy for the redesign of my site. Thanks for all the effort.

    0
  6. 6

    Nice compilation :)

    -1
  7. 7

    This is one heck of a collection. I could spend days seeing this. Lovely!!! I am in love with that rainbow color thing. It is super cool.. thanks for the round up :)

    -1
  8. 8

    Awesome article!!! Star to it!

    -1
  9. 9

    That Browser Pong is great!

    The twitter-style login demo is great too :D

    0
  10. 10

    AWESOME article. Question, though. I would like to view the “CSS 100% Height” technique, but the text and image hyperlink goes to a page and domain with no content and source code. Anyone else with this problem?

    0
  11. 11

    Great! Thank you!

    0
  12. 12

    Smashing Editorial

    February 18, 2010 6:39 am

    The site must be down at the moment – please try again later.

    -2
  13. 13

    Amazing collection, bookmarked ! A lot of tricks that can be usefull and avoid headaches for sure. Thanks !

    0
  14. 14

    Definitely a great roundup with helpful demos. I still suck at styling forms and some of the demos will help me next time for sure.

    1
  15. 15

    very nice collection – good post, thanks

    -1
  16. 16

    Nice article but they missed to include.. http://ib.im/dxfrH
    But will surely bookmark it :)

    0
  17. 17

    Really Awesome!,
    Thank you.

    0
  18. 18

    The site must have gotten the Smashing Effect. :D

    -2
  19. 19

    I love it! Great post! Hope to see more things like these in the future! A+ to SM!!

    1
  20. 20

    Very nice round-up. I’ve seen a lot of these and there are actually a couple of new techniques that I’m not familiar with.

    By the way, I already subscribe to a lot of these blogs, Soh Tanaka, Janko at Warp Speed, AEXT, Tutorialzine and CSS-Tricks.

    1
  21. 21

    Fantastic set of resources…. as always. :)

    1
  22. 22

    Kartlos Tchavelachvili

    February 18, 2010 12:47 pm

    Tricks, Tricks and more Tricks! This kind of articles are very useful! Thanks :)

    1
  23. 23

    Great roundup, extremely useful.
    Thanks a lot :D

    1
  24. 24

    Not sure if you guys know this or not, but in IE 8, your site redirects to the mobile version of the site!

    2
  25. 25

    Fantastic! Every new day i see new powers of the CSS. you think that the unification of the way browsers read CSS would be good or inhibit creativity that you see here?

    1
  26. 26

    great article! Thx, its very useful for me :)

    2
  27. 27

    Once again. you made and awesome post!

    3
  28. 28

    Wow. What a great post a lot of really good stuff in here – thanks :)

    0
  29. 29

    This is just an amazing article!

    0
  30. 30

    Bravoooo….
    Nice collection of techniques.

    Thx Smash.

    0
  31. 31

    Really wonderfull stuff!

    Thx for this great collection…

    0
  32. 32

    Good stuffs ! Definitely bookmarked.

    1
  33. 33

    amazing techniques for web designers and developers.

    0
  34. 34

    MArtin van Drunen

    February 19, 2010 2:44 am

    Cool stuff!!!!

    0
  35. 35

    just another damn useful article!! thank you!

    0
  36. 36

    Free Calculate your website worth: no tool needed……

    websitereckon.com

    thanks

    -1
  37. 37

    BuySellSwap Ireland

    February 19, 2010 4:06 am

    Fantastic article. I’m going to use some of these cool techniques soon.

    0
  38. 38

    marker css is a useful coding technique? seriously, guys?

    0
  39. 39

    Some really good stuff there. It’s given me a fair bit of inspiration!

    0
  40. 40

    PHADTOLOMEUS!, amazing article, muchas thank you!

    0
  41. 41

    Check lot of combination of jquery effects: http://idsreklama.com

    0
  42. 42

    One of my most favourite articles so far. A load of very brilliant techniques. Thank you!

    0
  43. 43

    Another Design Blog

    February 20, 2010 1:47 am

    Nice collection of articles! Looking forward…

    0
  44. 44

    Still Not Working I Also Would Like To Make It But Can’t Maybe Someone Can Email Them. Thanks Micah.

    -1
  45. 45

    Just great. I love it! thanks for sharing

    0
  46. 46

    Great Techniques , I Like it .. thanks for sharing …

    regards

    0
  47. 47

    Great CSS article. Some things I never knew you could do with pure CSS.

    Thanks,

    0
  48. 48

    Bookmarked site. very nice and useful tutorials.

    0
  49. 49

    jquery everywhere, boring.

    0
  50. 50

    This is an awesome collection. I have been looking good CSS form tutorials for one of my project. Thank for the article. I just bookmarked.

    0
  51. 51

    Thats Amazing

    lovely topic its very helpful

    regards

    -1
  52. 52

    thanks for share, very useful

    0
  53. 53

    Munnabhai- Dhanashree Inc

    April 5, 2010 3:14 am

    Nice CSS article. Some things I never knew you could do with pure CSS.Thanks,

    Thanks once agina.
    Munnabhai-Dhanashree Inc

    0
  54. 54

    I really can’t fathom how Smashing makes traffic any more. How many articles are just rips of other people’s blogs now? Try to compile the useful information for a change.

    1
  55. 55

    Great article!

    0
  56. 56

    really good article – thoroughly enjoy reading SM on a daily basis – great resource ;-)

    0
  57. 57

    This should have been the article title: 50 Useful Coding Techniques (CSS Layouts, Visual Effects and Forms)

    0
  58. 58
  59. 59
  60. 60

    Jose Miguel Bataller

    November 28, 2010 11:24 am

    nice collection and very useful!!!

    0
  61. 61

    I’d never thought css designing had evolve so fast. Guess I’ll be reading books again. Thanks.

    0
  62. 62

    Good looking out.
    There are many unique coding technologies that are used in the web. Article’s like these help to keep is simple.

    Thanx..

    P.s. My mashes = rdf->RSS->HTML,XML,PHP,CSS, JS + AS3/MXML

    0
  63. 63

    Really useful thx !!

    0
  64. 64

    great collection of great resource really helpful thanks :)

    0
  65. 65

    Amazing!
    TNX

    0
  66. 66

    Thanks a lot..
    It helped me a lot.

    0
  67. 67

    Yeah..
    Thanx..

    0
  68. 68

    I’m curious to find out what blog system you’re using?
    I’m experiencing some minor security problems with my latest blog and I’d like to find
    something more risk-free. Do you have any solutions?
    The Walking Dead Season 3 Episode 1 Online

    0
  69. 69

    it`s really nice collection…………………………..

    0

↑ Back to top