You’re probably familiar with CSS3 gradients by now, including the closer to the standard Mozilla syntax and the ugly verbose Webkit one. I assume you know how to add multiple color stops, make your gradients angled or create radial gradients. What you might not be aware of, is that CSS3 gradients can be used to create many kinds of commonly needed patterns, including checkered patterns, stripes and more.
View demo (Works in Webkit, Firefox 3.6+, Opera 11.50+ and IE10+)
The main idea behind the technique is the following, taken from the CSS3 Images spec:
If multiple color-stops have the same position, they produce an infinitesimal transition from the one specified first in the rule to the one specified last. In effect, the color suddenly changes at that position rather than smoothly transitioning.
I guess this makes it obvious how to create the tile for the stripes (unless you’ve never created a striped background before, but teaching you this is beyond the scope of this post). For example the gradient for the horizontal stripes is:
background-color: #0ae; background-image: -webkit-gradient(linear, 0 0, 0 100%, color-stop(.5, rgba(255, 255, 255, .2)), color-stop(.5, transparent), to(transparent)); background-image: -moz-linear-gradient(rgba(255, 255, 255, .2) 50%, transparent 50%, transparent); background-image: -o-linear-gradient(rgba(255, 255, 255, .2) 50%, transparent 50%, transparent); background-image: linear-gradient(rgba(255, 255, 255, .2) 50%, transparent 50%, transparent);
Why transparent instead of the actual colors we want? For flexibility. background-color serves two purposes here: Setting the color of half the stripes and serving as a fallback for browsers that don’t support gradients.
However, without anything else, the tile will occupy the whole container. To control the size of each tile, you can use background-size:
-webkit-background-size: 50px 50px; -moz-background-size: 50px 50px; background-size: 50px 50px;
To create the picnic-style pattern, you just overlay horizontal stripes on vertical stripes.
The hardest one to figure out was the checkered pattern. It consists of two 45° linear gradients and two -45° linear gradients, each containing ¼ of the dark squares. I still haven’t managed to think of a way to create a regular checkerboard (not at 45°) without needing an unacceptably large number of gradients. It will be very easily possible if conical gradients start being supported (currently they’re not even in the spec yet).
Can you think of any other popular patterns that can be created with CSS3 and no images? If so, let me know with a comment. Cheers!
Added afterwards: Other patterns
There are far more pattern designs possible with CSS3 gradients than I originally thought. For more details, see this later post.
Pingback: Striped and Checkerboard Backgrounds Without Images
Pingback: Striped and Checkerboard Backgrounds Without Images | The Hostmaster's Blog :: Web Hosting Tutorials | cPanel Guides | UK Unlimited Domain Web Hosting
Pingback: 99spaces – Freelance » Striped and Checkerboard Backgrounds Without Images
Pingback: My Stream » Striped and Checkerboard Backgrounds Without Images
Pingback: 画像を使用せずにCSSのみで作るストライプ、チェック、ボーダーなどの柄や、ボックスの角を折り曲げた様な背景エフェクト。 | BlackFlag
Pingback: Website optimization checklist
Pingback: Background Stripes & other patterns with CSS3 | Web Designers and Search Engine Optimizers
Pingback: Checkerboard, striped & other background patterns with CSS3 gradients « Spartan Pixel | News and much more
Pingback: Checkerboard, striped & other background patterns with CSS3 gradients | CREATIVE TWEETS
Pingback: Friday Focus 12/31/10: Go Big or Go Home | Devlounge
Pingback: RegexHacks :: Blog » Striped and Checkerboard Backgrounds Without Images
Pingback: Cross-browser CSS gradient buttons – Red Team Design
Pingback: <pro page="9 вещей, которые ты не знал о CSS3" />
Pingback: Checkerboard pattern with CSS3 | Lea Verou
Pingback: SWL-Projekt » Checkerboard pattern with CSS3
Pingback: Lea Verou Makes Background Patterns with CSS3 Gradients | Awesome But Useless
Pingback: Créer des motifs avec la propriété CSS3 gradient | Des souris et des plumes
Pingback: CSS3 Progress Bars | Silver-Tab.com
Pingback: CSS3 Progress Bars « Jolly Science
Pingback: Linkdump #31: CSS^3. « Tomasz Kowalczyk
Pingback: CSS3 индикаторы загрузки (прогрес бары)
Pingback: Speed Up with CSS3 Gradients « Jolly Science
Pingback: Powerful New CSS Techniques and Tools - Smashing Magazine
Pingback: Powerful New CSS Techniques and Tools | redbey
Pingback: Powerful New CSS Techniques and Tools « e-wok.fr, le blog
Pingback: Powerful New CSS Techniques and Tools
Pingback: Powerful New CSS Techniques and Tools | Ruturaj Pradeep Kohok | Your Web Advisor
Pingback: Powerful New CSS Techniques and Tools | Remake Wordpress Theme
Pingback: Web Design » Blog Archive » Powerful New CSS Techniques and Tools
Pingback: Powerful New CSS Techniques and Tools | i know idea
Pingback: FairWay Web Development » CSS Techniques and Tools
Pingback: Powerful New CSS Techniques and Tools : Copy & Print Center
Pingback: New Advance CSS3 Techniques and Tools | 39Articles
Pingback: CSS3-Hintergrundmuster mit CSS3-Gradients erzeugen | kulturbanause blog
Pingback: Patrones con degradados en CSS3 | Kabytes
Pingback: Powerful New CSS Techniques and Tools « qeqnes | Designing. jQuery, Ajax, PHP, MySQL and Templates
Pingback: Powerful New CSS Techniques and Tools | CRICKET ka FUNDA
Pingback: Powerful New CSS Techniques and Tools | test1
Pingback: Powerful New CSS Techniques and Tools | test2
Pingback: Various Background Patterns With CSS3 – Free | ignacio.com.mx
Pingback: Creating patterned backgrounds with CSS | My Blog
Pingback: Using CSS3 gradients to create text leading lines | Otto Rask
Pingback: CSS3 渐变背景图案 - 网页设计 - css - 九十度
Pingback: Cool notification messages with CSS3 & Jquery – Red Team Design
Pingback: Powerful New CSS Techniques and Tools | Sejix Technologies Blog
Pingback: Checkered Background Pattern Using only CSS « Authoring 1 Summer 2011
Pingback: aHmetfatiH » Blog Archive » CSS Renk Geçişleri (Gradients)
Pingback: Powerful New CSS Techniques and Tools | Inspire Technologies
Pingback: Is it possible to create a grid-like background in CSS without images or tables? | SeekPHP.com
Pingback: CSS3 Progress Bars - SevenSpark
Pingback: CSS3 Patterns Gallery |
Pingback: New CSS Techniques and Tools | W Design Love | Graphic and Web Design Blog | Coding | tutorials | freebies | Wordpress | inspiration | Blog
Pingback: CSS3グラデーションのスピードアップを図る! - CSSPRO
Pingback: CSS3Pie, styles CSS3 pour Internet ExplorerMontserrat Agence de Communication | Montserrat Agence de Communication
Pingback: CSS3 Tips: ボタン | Studio GAKI !
Pingback: 佈景主題:Crochimera 1.0 | Lab Crocodile
Pingback: Galería de Fondos Gratuitos de Lea Verou para paginas webs hechos con solo CSS3 sin usar Imágenes | PabloMetal Diseño web y temas interesantes desde Panamá
Pingback: Quack Ado
Pingback: CSS3で作られたストライプを、ユーザのカスタマイズした背景色に合わせて出力する | CHECKO Developer's Blog
Pingback: Animaciones 2D utilizando el Canvas de HTML5 | Maestros del Web
Pingback: Animaciones 2D utilizando el Canvas de HTML5 | The Last Blog
Pingback: Animaciones 2D utilizando el Canvas de HTML5 Noticias
Pingback: Animaciones 2d utilizando Canvas de HTML5 | BayWare
Pingback: CSS3 Styled Progress Bar | A Web Coding Blog
Pingback: 30 New Significant HTML5 And CSS3 Tips/Techniques/Tutorials | Tutsgeek.com
Pingback: st louis accident attorney