March 16, 2012

Image border on DIV

Question by Deryn

Is it possible to use an image of width 480px and height 360px and apply it to a div as a border? I know its possible to implement the below css code as a border, but I can not seem to work out how to use an image instead.

border:1px solid blue;

Answer by Starx

Actually, you can do this using a trick. Check out my demo using Google as border-image

Basically, the idea is having two divs.

<div id="borderDiv"><!-- This will serve as the border -->
    <div id="inner">
    </div>
</div>

CSS

#borderDiv {
    padding: 2px; /* This is the width of the border :P */
    background: url("borderimage.png");
}
#inner {
    background: #fff;
}

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!