tags:

views:

103

answers:

6

Client wants two color borders for an embossed look. Can I do this on one element? I was hoping to avoid stacking two DOM elements with individual borders.

A: 

If by "embossing" you mean two borders around each other with two different colours, there is the outline property (outline-left, outline-right....) but it is poorly supported in the IE family (namely, IE6 and 7 don't support it at all). If you need two borders, a second wrapper element would indeed be best.

If you mean using two colours in the same border. Use e.g.

border-right: 1px white solid;
border-left: 1px black solid;
border-top: 1px black solid;
border-bottom: 1px white solid;

there are special border-styles for this as well (ridge, outset and inset) but they tend to vary across browsers in my experience.

Pekka
I believe what he is asking is something like `border : black white; ` which means defining two different colors for one border which looks sequentially at the same time.
Braveyard
@Braveyard ah, I see. That would be theoretically possible using `outline` but it won't work well in IE < 8
Pekka
A: 

Not possible, but you should check to see if border-style values like inset, outset or some other, accomplished the effect you want.. (i doubt it though..)

CSS3 has the border-image properties, but i do not know about support from browsers yet (more info at http://www.css3.info/preview/border-image/)..

Gaby
Nothing is impossible in programming world :P well I like making this statement all the time :)
Braveyard
@Braveyard, *chuckle* good point :)
Gaby
+5  A: 

Yep: Use the outline property; it acts as a second border outside of your border. Beware, tho', it can interact in a wonky fashion with margins, paddings and drop-shadows. In some browsers you might have to use a browser-specific prefix as well; in order to make sure it picks up on it: -webkit-outline and the like (although WebKit in particular doesn't require this).

This can also be useful in the case where you want to jettison the outline for certain browsers (such as is the case if you want to combine the outline with a drop shadow; in WebKit the outline is inside of the shadow; in FireFox it is outside, so -moz-outline: 0 is useful to ensure that you don't get a gnarly line around your beautiful CSS drop shadow).

.someclass {
  border: 1px solid blue;
  outline: 1px solid darkblue;
}

Edit: Some people have remarked that outline doesn't jive well with IE < 8. While this is true; supporting IE < 8 really isn't something you should be doing.

Williham Totland
Sadly, `outline` doesn't work at all in IE6/7.
Pekka
-1 for "supporting IE < 8 really isn't something you should be doing". Not supporting IE6 may be fine. But not supporting IE7 is ridiculous, no site with a non-technical audience can afford this
Pekka
`outline` has been around since CSS2.
BoltClock
A: 

Simply write

style="border:medium double;"

for the html tag

Wazzy
That gives two borders with but one color between them.
Williham Totland
A: 

Another way is to use box-shadow:

#mybox {
box-shadow:
  0 0 0 1px #CCC,
  0 0 0 2px #888,
  0 0 0 3px #444,
  0 0 0 4px #000;
-moz-box-shadow:
  0 0 0 1px #CCC,
  0 0 0 2px #888,
  0 0 0 3px #444,
  0 0 0 4px #000;
-webkit-shadow:
  0 0 0 1px #CCC,
  0 0 0 2px #888,
  0 0 0 3px #444,
  0 0 0 4px #000;
}

<div id="mybox">ABC</div>

See example here.

livibetter
+1, this is great, but will not work in any IE ..
Gaby
A: 

Have you tried the different border styles available within the CSS spec? There's already two border styles that might accommodate your need:

border-style: ridge;

Or

border-style: groove;
JAG2007