Here is an example of the HTML structure to use: ( see explanation below )
<div class="container">
<div class="left"></div>
<div class="right"></div>
<div class="bot"></div>
</div>
And here is the CSS code to include:
.container {
position: relative;
padding: 5px; // adjust according to border image size
}
.container .left {
position: absolute;
left: 0;
top: 0;
background: url(border_left.jpg) repeat-y;
width: 5px;
height: 100%;
}
.container .right {
position: absolute;
right: 0;
top: 0;
background: url(border_right.jpg) repeat-y;
width: 5px;
height: 100%;
}
.container .bot {
position: absolute;
left: 0;
bottom: 0;
background: url(border_bot.jpg) repeat-x;
width: 100%;
height: 5px;
}
The concept behind this code is as follows:
- Create a container with relative positioning so that absolute positioned elements inside it will be positioned within its boundaries. The container also has padding equal to the width / height of the border images.
- Add three divs inside the container that are aligned to the left, right, and bottom edges of the container, stretching across the width / height.
To see a visual representation, check out this jsFiddle which uses background colors instead of images.
Note that the borders may overlap at the corners, which can be resolved by creating additional corner images to position in those areas.