开发者

Give a CSS styled div a "border-left-image"

Just trying to give the main content div on a site a border on the left and right side of the div. Rather than have separate divs for each border, I thought to 开发者_如何学编程use the border-left-image capability in CSS3 to make it happen. My code is as follows:

#content {
    background-color: #7FC3F4;
    height: 100%;
    width: 900px;
    border-left-width: 30px;
    border-left-image: url(../images/border_left_gradient.png);
    border-right-width: 30px;
    border-right-image: url(../images/border_right_gradient.png);
    margin-right: 10%;
    margin-left: 10%;
}

Of all the Google searches I've done, I have to yet to come up with an explanation as to why this code isn't valid. Some results return numeric values to be placed after the url, however regardless of what combination of numbers I try, no dice.

Thoughts?


border-image is now supported in all the major browsers (2014-05-22)

Demo with a single border-left-image

Demo with different left and right images.

The demos now need a minimum of Chrome 15, Safari 6, Firefox 15, IE 11 or Opera 15.

It is not actually possible to do this with separate image files, but you can slice a single image on the left and right. See the border-image page on MDN which shows some good examples or CSS Tricks for a comprehensive summary of how the other slicing options work.

Note: if you need earlier browser support please ask as a previous version of my answer did work with Chrome 12, Safari 5.0.3, Firefox 4 and Opera 10 but I have updated it now that new browsers support prefix-free CSS3.

Edit: Firefox now requires an additional property setting - border-style: solid (see CSS - New Firefox-release doesn't show Border-Image anymore)


Good solution : Chrome AND Firefox compatibility :

http://jsfiddle.net/Yas34/954/

missing border-style: solid to current "good answer"


For one your url is bogus (..images?). for a second have you checked your browser supports the property? last I checked, which wasn't that long ago, nobody supported it (well maybe webkit nightlies).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜