DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Elevating Web Design: The Art and Science of CSS Nesting and the Cascade
  • Creating Scrolling Text With HTML, CSS, and JavaScript
  • Why React Router 7 Is a Game-Changer for React Developers
  • How to Create a Pokémon Breeding Gaming Calculator Using HTML, CSS, and JavaScript

Trending

  • GCP Secret Manager, Live-Reloaded in Go With mamori
  • Stop Debugging Code That Works: Identifying False Failures in Kubernetes
  • How to Write for DZone Publications: Trend Reports and Refcards
  • Engineering Audit-Ready Data Pipelines for Regulatory Reporting

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Languages
  4. Multiple Backgrounds: Oh, What a Beautiful Thing.

Multiple Backgrounds: Oh, What a Beautiful Thing.

By 
Chris Coyier user avatar
Chris Coyier
·
Jan. 21, 08 · News
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
11.1K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in
The current spec for CSS3 includes support for multiple backgrounds in the background property. This is going to be fantastic for semantically-minded CSS developers. Many of the extra hooks that get thrown into HTML are there only to help out extra background images.

Think about this common technique for blockquotes.
<blockquote><span>
This is some blockquoted text.
</span></blockquote>

The extra span in there is completely un-semantic, but it is often used so that you can get an extra background image in there. One for the quote mark in the upper left and one for the quote mark in the lower right:

[img_assist|nid=349|title=|desc=|link=none|align=center|width=500|height=149]
Blockquote example from here.

With multiple backgrounds the extra hook is not needed. You can apply both the upper left and lower right image both to the blockquote element. Here is what the CSS will look like:
blockquote {
  background: 
    url('left.jpg') top left no-repeat,
    url('right.jpg') top right no-repeat,
    url('middle.jpg') top center repeat-x;
}

Notice you can set both the location and how it will repeat in each of the comma-separated backgrounds. I like the clean syntax of this, but it does present a problem. It is not backwards-compatible whatsoever. Older browsers that are not supporting this will just see no background at all, instead of for example, just the first image which would make sense. That means we can't just start using this in a forward-enhancement movement, unless we declare browser-specific stylesheets for the browsers that support it. At the time of this writing, only Safari is supporting multiple backgrounds.

Here is a link to a quick example of some buttons utilizing multiple backgrounds in order to shrink and grow seamlessly. Remember, Safari-only right now. Remind you of anything? Sliding doors. Multiple backgrounds completely absolute sliding doors.

Better semantics... No more complicated work-around techniques.... Oh, what a beautiful thing.
CSS Hook Mark (designation) dev Property (programming) Syntax (programming languages) HTML Links Element

Opinions expressed by DZone contributors are their own.

Related

  • Elevating Web Design: The Art and Science of CSS Nesting and the Cascade
  • Creating Scrolling Text With HTML, CSS, and JavaScript
  • Why React Router 7 Is a Game-Changer for React Developers
  • How to Create a Pokémon Breeding Gaming Calculator Using HTML, CSS, and JavaScript

Partner Resources

×

Comments

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook