tags:

views:

167

answers:

4

I essentially wish to have a "ridge" style border but with custom colors. With border-style: ridge it seems you can't put different colours in, the browser just uses one slightly lighter and one slightly darker than the colour specified.

My current solution is this, but it's not ideal due to the extra <div>

<div id="header">
  <!-- block with border-bottom set to `1px solid #2e3436`-->
</div>
<div style="height: 1px; background-color: #fbe995;"></div>

The next item below this can't have its top border set to that colour (it has its own styles and is separate), so that idea is out. Is there anything else I can try?

+1  A: 

Not per the spec for CSS 3 (Section 8.5.3):

The color of borders drawn for values of 'groove', 'ridge', 'inset', and 'outset' depends on the element's border color properties, but UAs may choose their own algorithm to calculate the actual colors used.

Technically I suppose that "choose their own algorithm" could involve allowing the developer to set them, but no user-agent seems to do that at this point. Of course, even if they did, you'd have a solution for only that rendering engine.

Nick Bastin
A: 

Edit: please delete one. Double posted somehow, sorry.

There's no official way to do this, but you could probably mimic the effect. A ridged border is really just an inset border which itself has an outset border around it (which in turn is just a solid border with slightly different border colors for left/top and bottom/right).

Something along these lines should get you a pretty good approximation of what you want, or exactly what you were looking for.

 .inset{
      margin:0px;
      border: 1px inset #abc;
 }
 .outset{
      padding:0px;
      border:1px outset #cba;
 }

<div class='outset'>
     <div class='inset'>
          content goes here
     </div>
</div>
Chris Sobolewski
A: 
<style>
.a
{
        border: solid yellow 2px;
        border-top-color:red;
        border-left-color:red;

}
.b
{
        border: solid red 2px;
        border-top-color:yellow;
        border-left-color:yellow;
}
</style>
<div class='a'>
  <div class='b'>
        some text
  </div>
</div>
Ewan Todd
So pretty much what I just said? Except that this won't mimic the ridge effect where the top and left are a different color from the bottom and right...
Chris Sobolewski
Chris, Your HTML and mine are isomorphic. Our CSS approaches are different. If you think my example doesn't mimic the ridge effect, you must have overlooked something. For example, the styling for class 'a' initially defines a yellow border. The subsequent cascaded rules then change the border color to red on two sides. The two colors are inverted in the rule for class 'b'. Potentially, you could color all 8 border fragments differently using this approach.
Ewan Todd
+1  A: 

Your example seems to suggest you want to create a ridged line as a separator between your header and the rest, rather than a ridged border around an element. Why don't you use a hr for that, since that's pretty much exactly what it's for?

You can then give it a border and set your own colors on the different sides.

mercator
Of course! Didn't think of this.
DisgruntledGoat