Creating an "Body Border" with CSS
Join the DZone community and get the full member experience.
Join For Freecheck 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; }
original article here .
Opinions expressed by DZone contributors are their own.
Comments