There are many different ways. The hr
does not always react as expected, if you have no problem using another element, a simple way is this:
.hr {
border-top:1px solid #ccc;
border-bottom:1px solid #fff;
}
body {background:#eee}
1
<div class="hr"></div>
2
If you only support newer browsers, you can use rgba(0,0,0,.2)
and rgba(255,255,255,.2)
to work on any background (black and white with transparency .2
)
The same technique can be applied to hr
, but you have to be careful with the way elements are stylized in different browsers. In some cases, hr
is implemented with borders, in others as border + content.
CSS also has inset
for the same effect, but then you have less control over the light and dark part.
View the inset applied to a hr
:
hr {
height:0;
width:100%;
border:1px inset #eee;
}
body {background:#eee}
1
<hr>
2