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
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Programmatic Brand Extraction: Pulling Logos, Colors, and Assets from Any URL
  • The Death of the CSS Selector: Architecting Resilient, AI-Powered Web Scrapers
  • A Guide to Parallax and Scroll-Based Animations
  • Building a Card Layout Using CSS Subgrid

Trending

  • Architecting Autonomous Network Ecosystems: From Reactive Monitoring to Agentic AI Orchestration
  • API Facade vs. Orchestration vs. Eventing, Now With AI in the Loop
  • Your Agent Trusts That Wiki. Should It?
  • Your Automation Pipeline Is Not a Source of Truth
  1. DZone
  2. Coding
  3. Languages
  4. Creating an "Body Border" with CSS

Creating an "Body Border" with CSS

By 
Chris Coyier user avatar
Chris Coyier
·
Feb. 26, 08 · News
Likes (0)
Comment
Save
Tweet
Share
29.2K Views

Join the DZone community and get the full member experience.

Join For Free
hicksdesign has been " fiddling " with their site design. the new design features what someone called in the comments a "body border". it's basically a stroke of color just inside the entire viewable area, all the way around, in the browser window. i thought it was a nice touch and a pretty spiffy little css trick so i thought i'd feature how it was done here.

check out the example page .

the code



four unique page elements are neccecery. div's work fine for this:

<div id="left"></div>
<div id="right"></div>
<div id="top"></div>
<div id="bottom"></div>


here is the css for them. notice how clean the css can be. some properties are shared by all of the elements, some by only the top/bottom and left/right, and some unique to themselves. this css is coded like that, instead of repeating properties and values unnecessarily.

#top, #bottom, #left, #right {
	background: #a5ebff;
	position: fixed;
	}
	#left, #right {
		top: 0; bottom: 0;
		width: 15px;
		}
		#left { left: 0; }
		#right { right: 0; }
		
	#top, #bottom {
		left: 0; right: 0;
		height: 15px;
		}
		#top { top: 0; }
		#bottom { bottom: 0; }


browser compatibility



works great in firefox, safari, and opera, and ie 7. does it work in ie 6 (or below)? of course not! mostly has to do with positioning. ie 6 doesn't love fixed positioning and the hacks i find ugly and not terribly reliable. the solution is just to ditch the body border for ie:

header html for conditional stylesheet (put comment tags around this in use):

[if lte ie 6]>
    <link href="/ie6.css" type="text/css" rel="stylesheet" media="screen" />
<![endif]


css to remove body border:

#top, #bottom, #left, #right { display: none; }


bodyborder.png

original article here .
CSS

Opinions expressed by DZone contributors are their own.

Related

  • Programmatic Brand Extraction: Pulling Logos, Colors, and Assets from Any URL
  • The Death of the CSS Selector: Architecting Resilient, AI-Powered Web Scrapers
  • A Guide to Parallax and Scroll-Based Animations
  • Building a Card Layout Using CSS Subgrid

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • 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