SEO

July 18, 2011

Nicolas Gallagherstein

Multiple Backgrounds with CSS 2.1

Read the article: Multiple Backgrounds and Borders with CSS 2.1.

You can find me on twitter.

1310891850
Ad73cd057df565ea0d3225b3f902b24d
A100927d48d24256bef9fb7641f0f8
1310891996
C44eed9f810832b4651f15a0ac2db0
Aa63d4b327e2108d8e9e8336ce5f73

Fluid faux columns without images. Source independent. The use of rgba background is only to show the area of each box. No problem putting links in the content ( #non ). The markup for this section looks like this: ---------------------- Supp2: Third in source ---------------------- Sed accumsan neque a nisi luctus volutpat. Quisque placerat nibh ac leo varius non varius lacus cursus. Curabitur bibendum volutpat eleifend. Nullam sit amet dolor massa. Nunc consectetur ornare purus, et euismod nunc cursus at. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec aliquet leo nec quam vestibulum non mattis odio dapibus. Curabitur consequat odio odio. Proin a justo at lorem ultricies hendrerit. Sed accumsan neque a nisi luctus volutpat. Quisque placerat nibh ac leo varius non varius lacus cursus. Curabitur bibendum volutpat eleifend. Nullam sit amet dolor massa. Nunc consectetur ornare purus, et euismod nunc cursus at. Vestibulum ante ipsum primis in faucibus orci. Dribbble style buttons without images ( http://dribbble.com ) This example uses one element and one image (a sprite). Using pseudo-elements for additional background-images lets you clip sprites and fake the positioning of a background image from any side (not just the top and left). [content] Images that break out of the box are a popular effect. This is easy to achieve with pseudo-elements. No need for images in the markup, nested elements, or empty elements. Depending on the look you're after you can absolutely position or float the pseudo-element. This technique gives you a lot of flexibility over the positioning of presentational imagery. They can be part of the normal flow; or content can flow around them (float); or they can be removed from the document flow entirely and positioned from any side (absolute/fixed positioning). This example floats the pseudo-element so the main content's text will wrap around this image. [content] [content] An element with the popular folded-corner effect (with CSS only), two background images, and a generated-content image. P.S. Don't let your designer friends see my comic sans [content] You can find me on twitter ( http://twitter.com/necolas ). Multiple Backgrounds and Borders with CSS 2.1. You'll have to view the CSS file because Firebug won't show pseudo-elements.Nicolas Gallagher

********************************* Multiple Backgrounds demo for Silverback ( http://silverbackapp.com/ )'s parallax effect with more gorillas. [content] --------------------- Main: First in source ---------------------

Fit for purpose

Resize your browser. How wide am I?

Only one element to reproduce Silverback's parallax effect with more gorillas.
<div id="silverback">[content]</div>

Main: First in source

Fluid faux columns without images. Source independent. The use of rgba background is only to show the area of each box.

No problem putting links in the content. The markup for this section looks like this:

Multiple Borders with CSS 2.1

By Nicolas Gallagher

Multiple Borders demo for Multiple Backgrounds and Borders with CSS 2.1. You'll have to view the CSS file because Firebug won't show pseudo-elements.

Fit for purpose: Firefox 3.5+, Safari 4+, Chrome 4+, Opera 10+, Internet Explorer 8+.

A div containing some content
A div containing some content
A div containing some content
A div containing some content

A div with at least one child element provides 7 "borders".

 

Popular two-colour border without images
Up to 7 single-side "borders" from one element. Actually, 8 if you are prepared to show some of the element's background colour as a fake border.

FABW's complex borders

No images used to create these borders

Vivamus auctor, tellus vel dictum pulvinar, a congue elit odio vel enim. Quisque fringilla semper fermentum. Nulla a felis a diam dapibus accumsan.

Supp1: Second in source

Vivamus auctor, tellus vel dictum pulvinar, a congue elit odio vel enim. Quisque fringilla semper fermentum. Nulla a felis a diam dapibus accumsan. Etiam varius fringilla magna sit amet hendrerit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.

Supp2: Third in source

Sed accumsan neque a nisi luctus volutpat. Quisque placerat nibh ac leo varius non varius lacus cursus. Curabitur bibendum volutpat eleifend. Nullam sit amet dolor massa. Nunc consectetur ornare purus, et euismod nunc cursus at. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec aliquet leo nec quam vestibulum non mattis odio dapibus. Curabitur consequat odio odio. Proin a justo at lorem ultricies hendrerit.

Sed accumsan neque a nisi luctus volutpat. Quisque placerat nibh ac leo varius non varius lacus cursus. Curabitur bibendum volutpat eleifend. Nullam sit amet dolor massa. Nunc consectetur ornare purus, et euismod nunc cursus at. Vestibulum ante ipsum primis in faucibus orci.

This example uses one element and one image (a sprite).

Using pseudo-elements for additional background-images lets you clip sprites and fake the positioning of a background image from any side (not just the top and left).

<div id="sprite">[content]</div>

The background can even live outside the box

Images that break out of the box are a popular effect. This is easy to achieve with pseudo-elements. No need for images in the markup, nested elements, or empty elements.

Depending on the look you're after you can absolutely position or float the pseudo-element. This technique gives you a lot of flexibility over the positioning of presentational imagery. They can be part of the normal flow; or content can flow around them (float); or they can be removed from the document flow entirely and positioned from any side (absolute/fixed positioning).

This example floats the pseudo-element so the main content's text will wrap around this image.

<div id="outside"> <div class="hero">[content]</div> <div class="main">[content]</div> </div>

An element with the popular folded-corner effect (with CSS only), two background images, and a generated-content image.

P.S. Don't let your designer friends see my comic sans

<div id="corner">[content]</div>

Jquery for Designers uses nested div's and 3 images on its About page to create this effect. Using pseudo-elements as background canvases, just one element is needed.

<div id="j4d">[content]</div>
http://nicolasgallagher.com/multiple-backgrounds-and-borders-with-css2/demo/v... http://nicolasgallagher.com/multiple-backgrounds-and-borders-with-css2/demo/f... http://nicolasgallagher.com/multiple-backgrounds-and-borders-with-css2/demo/p... http://nicolasgallagher.com/multiple-backgrounds-and-borders-with-css2/demo/j..." border="0" />

Read the article: Multiple Backgrounds and Borders with CSS 2.1.

9th Jun 2010

About me

I'm a London-based freelance Front-End Web Developer, CSS researcher and hacker, co-creator of Normalize.css, and contributor to the HTML5 Boilerplate project.

The organisations I've done work for include ASOS, Central Office of Information, The Department of Health, Arthritis Research UK, Natural England, and UCL. Further information is available in my résumé.

This is my personal blog. I write here – usually on topics related to front-end development – as part of engaging with, and learning from, other developers.

nicolas@nicolasgallagher.com. Copyright © 2011 Nicolas Gallagher.

Original code is dual licensed under the MIT and GNU GPLv2 licenses. Original photographs and text are licensed under a Creative Commons BY-SA license.

Vivamus auctor, tellus vel dictum pulvinar, a congue elit odio vel enim. Quisque fringilla semper fermentum.

 

You can find me on twitter.

Multiple Backgrounds with CSS 2.1 Read the article: Multiple Backgrounds and Borders with CSS 2.1 . You can find me on twitter . Fluid faux columns without images. Source independent. The use of rgba background is only to show the area of each box. No problem putting links in the content ( #non ). T ...»See Ya

"Use SVG", "CSS is not meant for this", "blah blah" - yes, I know. Thanks

Style sheets in http://nicolasgallagher.com/lab/html5-logo-in-css2/

Inline style sheet

/*  * "Use SVG", "CSS is not meant for this", "blah blah" - yes, I know. Thanks * Looks best in Firefox 3.6+ and Chrome. Edges are jagged in IE 8 and Opera. * * Nicolas Gallagher (20 Jan 2011) */  html { position:relative; width:364px; height:512px; padding:0; margin:50px auto 0; }  body { padding:0; margin:0; }  h1 { width:100%; height:100px; padding:0; margin:0 0 450px; font:100px/60px 'Arial Black', sans-serif; text-align:center; }  h2 { overflow:hidden; height:0; padding:0; margin:0; text-indent:-999em; }  p { text-align:center; font:14px/1.2 Arial, sans-serif; }  p a { font-weight:bold; color:#D14926; }  /* ------------- LOGO SHAPES ------------- */  html:before, html:after, body:before, body:after, header:before, header:after, h1:before, h1:after, h2:before, h2:after { content:""; position:absolute; }  /* Main shield */  html:before, html:after { z-index:1; left:2px; top:100px; width:292px; border-width:374px 34px 0; border-style:solid; border-color:#e44d26 transparent transparent; }  html:after { left:35px; top:474px; width:0; border-width:40px 146px 0; border-top-color:#e44d26; }  /* Brighter panel of the shield (right side) */  body:before { z-index:2; left:182px; top:130px; border-width:318px 28px 34px 120px; border-style:solid; border-color:#f16529 transparent transparent #f16529; }  /* Top right chunk of "5" */  body:after { z-index:3; left:182px; top:175px; border-width:45px 4px 0px 110px; border-style:solid; border-color:#fff transparent transparent #fff; }  /* Top left chunk of "5" */  header:before, header:after { z-index:3; left:68px; top:175px; border-width:138px 102px 0px 12px; border-style:solid; border-color:#ebebeb #ebebeb transparent transparent; }  header:after { left: 117px; top: 220px; border-width:48px 61px 0px 4px; border-color:#E44D26 #E44D26 transparent transparent; }  /* Bottom left chunk of "5" */  h1:before, h1:after { z-index:3; left:83px; top:335px; border-width:72px 93px 25px 6px; border-style:solid; border-color:#ebebeb #ebebeb transparent transparent; }  h1:after { left:128px; top:335px; border-width:39px 51px 13px 3px; border-color:#E44D26 #E44D26 transparent transparent; }  /* Bottom right chunk of "5" */  h2:before, h2:after { z-index:3; left:182px; top:268px; border-width:139px 11px 25px 94px; border-style:solid; border-color:#fff transparent transparent #fff; }  h2:after { left:182px; top:313px; border-width:60px 4px 14px 52px; border-color:#F16529 transparent transparent #F16529; }

/*
* "Use SVG", "CSS is not meant for this", "blah blah" - yes, I know. Thanks
* Looks best in Firefox 3.6+ and Chrome. Edges are jagged in IE 8 and Opera.
*
* Nicolas Gallagher (20 Jan 2011)
*/

Style sheets in http://nicolasgallagher.com/lab/html5-logo-in-css2/ Inline style sheet /* * "Use SVG", "CSS is not meant for this", "blah blah" - yes, I know. Thanks * Looks best in Firefox 3.6+ and Chrome. Edges are jagged in IE 8 and Opera. * * Nicolas Gallagher (20 Jan 2011) */ html { position:re ...»See Ya

step_5