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.
-
Are you willing to use Javascript to achieve the effect? http://jquery.malsup.com/corner/ – nopuck4you Oct 11 '10 at 17:34
13 Answers
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.

- 28,471
- 6
- 52
- 68
-
27-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 Oct 11 '10 at 14:36
-
6
-
158+1 for not supporting IE 7, while your site should always work and look reasonably well in IE 7, full support is not necessary. especially if it's just a two color border. i'm personally using box-shadow and other 'advanced' features. IE7 can't see a box-shadow, ... big deal. there is no reason to use a less suited, overly complicated, or even outdated solution, just to work around IE7s quirks. – Marian Theisen Sep 30 '11 at 19:57
-
2Also, see this reference for good accessibility reasons NOT to hack the outline property for design purposes: http://www.outlinenone.com/ – Joel Glovier Jun 14 '12 at 16:23
-
11A word of caution, `outline` is less versatile than `border`. In particular, [W3C says](http://www.w3.org/TR/CSS21/ui.html#propdef-outline): "Note. The outline is the same on all sides. In contrast to borders, **there is no 'outline-top' or 'outline-left' property**." _(Emphasis mine.)_ – Bob Stein Feb 20 '13 at 03:05
-
`outline` is a simple paint and doesn't interact with `margin` or `padding`. You **never** need to "use a browser-specific prefix as well". – sam Jan 23 '14 at 17:09
-
2`outline` is not compatible with `border-radius` now and in the future, please update answer – Daniel Cheung Jan 16 '15 at 11:03
This is very possible. It just takes a little CSS trickery!
div.border {
border: 1px solid #000;
position: relative;
}
div.border:before {
position: absolute;
display: block;
content: '';
border: 1px solid red;
height: 100%;
width: 100%;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
<div class="border">Hi I have two border colors<br />I am also Fluid</div>
Is that what you are looking for?

- 2,070
- 3
- 29
- 47

- 1,073
- 1
- 9
- 9
-
Indeed it's tricky, but it degrades gracefully and even works on my HTC's stock browser (Android)! If you use `border-radius`, try reducing the inner border's radius by one pixel, that will make the gap between the two rounded borders nearly unnoticable. – flu Nov 22 '11 at 16:14
-
This is nice. Using `bottom:1px` rather than `height:100%` worked better for me for just a bottom border :) – Nick Jan 19 '13 at 06:14
-
if you have a padding for the `div.border`, I found that adding a negative margin with the same dimensions for the `div.border:before`, helped to keep everything inline. Maybe there's a better way to do it? [jsFiddle](http://jsfiddle.net/qcvbD/1072/) – NW Tech Jan 23 '14 at 22:23
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.

- 19,832
- 3
- 42
- 42
-
1I prefer this since it works with border-radius unlike the outline method – Johan van den Broek Jun 07 '17 at 11:17
Outline is good, but only when you want the border all around.
Lets say if you want to make it only on bottom or top you can use
<style>
#border-top {
border-top: 1px solid #ccc;
box-shadow: inset 0 1px 0 #fff;
}
</style>
<p id="border-top">This is my content</p>
And for bottom:
<style>
#border-bottom {
border-top: 1px solid #ccc;
box-shadow: 0 1px 0 #fff;
}
</style>
<p id="border-bottom">This is my content</p>
Hope that this helps.

- 199
- 1
- 3
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;

- 7,469
- 9
- 51
- 86
Instead of using unsupported and problematic outline just use
- background-color + padding for the inner border
- normal border for the outer one.
Example:
HTML:
<img src="http://cdn3.thumbs.common.smcloud.net/common/8/6/s/863444wpPN.jpg/r-0,500-n-863444wpPN.jpg" alt="malkovich" />
CSS:
img {
padding: 1px;
background: yellow;
border:1px solid black;
}
TEST(JSFiddle):
img {
padding: 1px;
background: yellow;
border: 1px solid black;
}
<img src="http://cdn3.thumbs.common.smcloud.net/common/8/6/s/863444wpPN.jpg/r-0,500-n-863444wpPN.jpg" alt="malkovich" />

- 2,070
- 3
- 29
- 47

- 79
- 1
- 1
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.

- 442,112
- 142
- 972
- 1,088
-
3I 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. – Tarik Oct 11 '10 at 14:15
-
1@Braveyard ah, I see. That would be theoretically possible using `outline` but it won't work well in IE < 8 – Pekka Oct 11 '10 at 14:18
-
3Note that there is only outline... there is no such thing as outline-left, outline-right, outline-top, or outline-bottom unfortunately. – David Sherret Jun 29 '12 at 00:41
Easily use two colors by using a border on two dives
<div class="border-shadow">
<div class="nav-bar">
<!-- <a href="../home-page.html">HOME</a> -->
<a class="a-no-underline" href="page4.html">Apps</a>
</div>
</div>
.border-shadow {
border-top: 3px solid white;
border-bottom: 3px solid black;
}
.nav-bar {
display: flex;
align-items: center;
justify-content: space-around;
border-top: 3px solid black;
border-bottom: 3px solid white;
}

- 11
- 1
Adding the following CSS properties to a border will achieve a double border of two distinct colors and identical widths for those who are interested.
Example:
Selector {
border: 10px red;
border-block-start-style: ridge;
border-inline-start-style: ridge;
border-inline-end-style: groove;
border-block-end-style: groove;
}

- 28
- 4
You could use
<html>
<head>
<title>Two Colors</title>
<style type="text/css">
.two-colors {
background: none repeat scroll 0% 0% rgb(245, 245, 245); border-color: rgba(111,111,111,0.2) transparent;
padding: 4px; outline: 1px solid green;
}
</style>
<style type="text/css">
body {
padding-top: 20px;
padding-bottom: 40px;
background-color:yellow;
}
</style>
</head>
<body>
<a target="_blank" href="people.htm">
<img class="two-colors" src="people.jpg" alt="Klematis" width="213" height="120" />
</a>
</body>
</html>

- 1
- 29
- 94
- 165
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/)..

- 191,379
- 34
- 261
- 317
-
Nothing is impossible in programming world :P well I like making this statement all the time :) – Tarik Oct 12 '10 at 01:06
This produces a nice effect.
<div style="border: 1px solid gray; padding: 1px">
<div style="border: 1px solid gray">
internal stuff
</div>
</div>

- 1,206
- 10
- 19