tags:

views:

32

answers:

3

Hi, I want to create a button with two solid borders around eachother, like this:

.--------.
|.------.|
||Button||
|'------'|
'--------'

Of course I can do it this way by wrapping the button into an evil, bandwidth-consuming <span>:

<span class="outer-border">
    <a class="button" href="http://www.example.com/"&gt;Button&lt;/a&gt;
</span>

.outer-border { border: solid 1px red; } .button { border: solid 1px green; }

But isn't there a cleaner way than using too much HTML? Is there a way to add two borders to just one selector? Namely, I also want to do this with an XML file which can't be modified, of course.

Could anyone help me? Thanks.

+2  A: 

There's the outline property but it's not supported by IE 6 and 7 (compatibility table here).

I'd go with the span.

Pekka
Yep, the span works, but I can't use it with XML files. That's the little problem..
Time Machine
@Koning an XML file containing HTML? Can you elaborate? (Edit: Aaah, you mean you are working with existing content. Hang on, thinking....)
Pekka
@Koning nope, apart from `outline` (which is less flexible in styling than `border`, it accepts only one style for all sides) I can't think of an alternative to adding a wrapping element, not even using CSS trickery like `:before` etc.
Pekka
Oh, about the IE problem: IE users are used to bad looking webpages and burning eyeballs, so I don't care about such a little beauty-failure. But can I also make the outline property work with the border-radius property?
Time Machine
@Koning Yes in Firefox: https://developer.mozilla.org/en/CSS/-moz-outline-radius No in IE8: http://msdn.microsoft.com/en-us/library/cc351024%28VS.85%29.aspx No in Webkit: http://doctype.com/webkitoutlineradius-does-exist
Pekka
And by the way, what about a border image with dimensions of 1x2 pixels?
Time Machine
@Koning maybe - haven't looked into those yet. But they are even less well supported than outlines - I think in FF only since 3.6 for example.
Pekka
A: 

If it is not vital that the borders have different colours then you could use border-style:double

Dan Iveson
Actually I already solved everything by making the border darker so it looks good. I'll let the question here for all those peeps who also want two differently colored borders.
Time Machine
+1  A: 

It is possible, using CSS 3 box shadows, which are supported in Chrome 5 and Firefox 3.5.

I'm not sure if it'll work in IE, but it will sooner or later.

Here is a useful article: http://weston.ruter.net/2009/06/15/multiple-borders-via-css-box-shadow/

And the W3C definition at http://www.w3.org/TR/css3-background/#box-shadow

Specifically, to do your one, use (on Chrome/Safari/Firefox)

.button {
    margin: 4px;
    -webkit-box-shadow: 0 0 0 1px green, 0 0 0 2px white, 0 0 0 1px green;
    -mox-box-shadow: 0 0 0 1px green, 0 0 0 2px white, 0 0 0 1px green;
}

The box shadows are not included in the boxing model, so you need to set a margin to the size of your borders.

Vincent McNabb