...

View Full Version : CSS Custom Image Borders



JustinSainton
09-18-2006, 08:28 AM
Hey all,

I am working on a site, and for some reason, they want it so that the borders are a kind of stamp pattern rather than a normal border. Is there a decently semantic way to do this without JS the causes it to work both functionally and semantically?

I've got kind of a start at http://www.premierpostage.com/index1.php

You'll notice, in FF at least, that the top and bottom are kosher, the sides obviously push the content down and aren't exactly expandable. Any help would be much appreciated!

VIPStephan
09-18-2006, 10:04 AM
I suppose this is going to be a fixed width? Then you can make the side borders one image with as much space in between as the content is wide. You would then use the elements you have to apply the images as background, e.g.:


<div id="container">
<div id="header"></div>
<div id="content"></div>
<div id="footer"></div>
</div>

In this scenario you can apply the side borders to the container div, the top border as background to the header div, and the bottom border to the footer div.

JustinSainton
09-18-2006, 08:57 PM
I tried something akin to that.

If you view the source code, there is essentially a container div that has two divs in it for the left pattern and the right pattern that are supposed, as seen in the CSS, extend 100% of the height of the container, repeating on the y axis. Why it's not working, I'm not entirely sure.

The CSS is more or less as follows:



#stampleft {width: 6px; height:50em; background: url(../images/leftsidestamp.gif); background-repeat:repeat-y; float:left; margin-left:-4px}
#stampright {width: 6px; height:50em; background: url(../images/rightsidestamp.gif); background-repeat:repeat-y; float:right; margin-right:-4px}
#container {width:791px; margin:0 auto; border:1px solid #fff }

VIPStephan
09-18-2006, 09:53 PM
But that's not even necessary! I mean those two divs just for the images. Always try to use as much HTML as necessary but as few as possible.

You can just combine those two images and put them in the container itself. They would automatically repeat as much as the container's height is increasing.

Look at this CSS Zen Garden submission (http://csszengarden.com/?cssfile=/191/191.css&page=0), especially at the background image (http://csszengarden.com/191/cover.png). That's basically the same approach. Two borders as one image with as much space in between as the content will be wide.

JustinSainton
09-18-2006, 10:44 PM
I think I understand, would I then just apply the border to the container div as a plain border or as border-left/right? I guess i can just test around a bit. Thanks!

VIPStephan
09-18-2006, 11:35 PM
No, as the guy with the CSS Zen Garden Design you would apply this image as background image. Remember, that's just an image displaying two borders... so it's like "fake borders". You aren't applying borders to the div but a background image which pretends the container has borders.

JustinSainton
09-19-2006, 06:14 AM
Thanks man, I think I got it!

VIPStephan
09-19-2006, 12:52 PM
Great! That's it! :)
Now, to extend this method apply the top border as background image to the header div and the bottom border in the same way to the footer div (positioned at the bottom, of course) and remove the actual <img> tags. Saving code, you know? ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum