- Show newest for...
- Twinkl Handwriting
- Twinkl Originals
- Early Years
- Key Stage 1
- Key Stage 2
- ESL/TEFL Resources
- Senior Leadership Team (SLT)
- Twinkl Move
- Home Education
- Twinkl Go
- Adult Education
- Scotland (CfE)
- Republic of Ireland
- New Zealand
- Northern Ireland
- مواد تعليمية عربية
- South Africa/Suid-Afrika
- América Latina y el Caribe
- Middle East
- Coming Soon
- Age 0-5
- Age 5-7
- Age 7-11
- Age 11-18
This article as originally published on February 25, 2008, but is now being completely re-written to be more comprehensive and show modern techniques.
Jon Hick's site Hicksdesign is where I first saw the concept of a "body border." In this case, it's a very subtle and lovely effect.
Characteristics of a body border:
- Go around entire browser window, stuck to the edge regardless of screen size
- All edges stay in place as page scrolls
- Content goes beneath borders as page scrolls
Technique #1: Four Divs
The way to do this with the deepest cross browser compatibility is to use four elements to do it. Hicksdesign does it this way, using four <b> elements and has this to say in an HTML comment:
I use the b tag borders because it's just visual stuff with no meaning so I may as well use the smallest tag I can find.
No matter what, this is presentational markup which is not ideal. We'll use a div here:
Then we style with CSS. Some properties are shared by all of the elements, some by only the top/bottom and left/right, and some unique to themselves. Here is a clean way to code that, without unnecessary repeated properties.
This should work fine in IE 7 and up and just about any other good desktop browser. For IE 6, which doesn't support fixed positioning, we'll just get rid of it (no harm no foul) by using a conditional comment in the head:
We also should ditch it on small screens (likely to be mobile) which also don't handle fixed positioning:
So now we get the effect where we want it and not where we don't:
Technique #2: Pseudo Elements
In the above example, we needed four unique elements to get the job done. But that's four more elements than are appropriate semantically in our document. Ideally we would use zero. Well wouldn't ya know it, there are two elements that are the size of the browser window already, the and elements. Using the :before and :after pseudo elements on those, we get four!
We would use the same properties and values as above, only we would use:
Harry Roberts had this idea as well and published it on CSS Wizardy.
While the browser support for pseudo elements is pretty good, it's not as good as Technique #1. A bigger problem is that there is an WebKit bug which the background on an html-element pseudo element bleed over the entire viewport. This makes using pseudo elements on the html-element a no-go for the time being.
But there is a solution! While saying semantic!
We don't really need four unique elements, we really only need two. The top and the bottom need to be unique, so they can be of fixed position and not scroll. For the left and the right, we can literally just use a on the .
Same exact effect, slightly less browser support, way more semantic.
For Funzies: Kottke.org body border
Jason Kottke's Kottke.org has a pretty cool body-border effect.
It takes Jason eight different elements and eight different images (!) to pull this off. Because this border style doesn't stay fixed to the top and bottom of the viewport (just the top and bottom of content) this is actually really easy to pull off with CSS3.
We'll use on the element, and it's neat ability to comma-separate multiple shadows. Here it is in it's entirety with
Bug Note: Opera (Mac, 11.10) has a weird bug where it expands the size of the element to accommodate for the shadows on the outside (even thought the shadows are inset). This triggers unwanted scrollbars, since we're using it on a full-width body element. Horizontal scrollbars can be hidden by hiding overflow-x. But unfortunately there will still be a bit of space at bottom of screen.
While this has the least browser support of all the stuff covered, it's not bad: IE 9+, Fx 3.5+, Opera 10.5+, Chrome any, Safari 3+