[web] Using images as a border with CSS.

Started by
4 comments, last by Etnu 18 years, 10 months ago
I'm tryint to put an image border around a DIV with CSS but can't quite figure out how. Right now I'm using a 3x3 table to create this effect, but want to switch to something more readable and less 1997. I've tried searching on google but only find stuff on putting borders around an image.
"The paths of glory lead but to the grave." - Thomas GrayMy Stupid BlogMy Online Photo Gallery
Advertisement
You'll need CSS3 for that. http://www.w3.org/TR/2005/WD-css3-background-20050216/#the-border-image

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

If you want to do a single border along one edge of a div, you can use a technique described in A List Apart's Custom Underlines article.
Thanks for the help, but so far CSS3 isn't fully supported, and the border-image property isn't supported at all.

And the other site posted only deals with underlineing, I need a full border.

I guess I'll jsut use tables.
"The paths of glory lead but to the grave." - Thomas GrayMy Stupid BlogMy Online Photo Gallery
No need to use tables! See http://www.alistapart.com/articles/customcorners/ for a good way to do this according to the webstandards. There's a part II for that article as well at http://www.alistapart.com/articles/customcorners2/

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

I usually recommend something like this, to minimize the extra markup:

<div class="outer"><p>Here's some content...joy</p><img src="bottom-right.gif" class="bottom"/></div>


CSS looks something like this:

div.outer{  background: url(top-left.gif) top left no-repeat;}div.outer *{  background: url(top-right.gif) top right no-repeat;  margin: 0;  padding: 0;}img.bottom{  background: url(bottom-left.gif) bottom left no-repeat;  display: block;  margin: 0;  padding: 0;  border: none;  padding-left: 100px;}


Tweaked as necessary.

The net result of this is that only 2 additional tags are required to put a border around an element. It's not perfect, and there may very well be some browsers out there that don't allow background images on images, but so far it seems to work on stuff I've tried it out on, but it's a nice and clean solution without the mess of using multiple nested tags (tables or otherwise) to do the trick.

---------------------------Hello, and Welcome to some arbitrary temporal location in the space-time continuum.

This topic is closed to new replies.

Advertisement