Create a “inset” effect using CSS in websites

2019-02-02 00:32发布

I am very much impressed by the "inset" like effect in many latest websites. Some examples are alt text http://img687.imageshack.us/img687/457/inset2.png

and

alt text http://img163.imageshack.us/img163/8158/inset1.png

The line in the center. Nowadays, many websites use these kinds of lines/effects.

I tried to achieve the same with borders but the color combination is not working me and it is not proper.

Do other websites use images for these ? is it easy to this ?

Any example css ?

Example sites: http://woothemes.com, http://net.tutsplus.com/ , http://www.w3schools.com (in the header) and in wordpress admin page sidebar

8条回答
家丑人穷心不美
2楼-- · 2019-02-02 01:16

Don't know if this will help, but using 1 px borders that are slightly lighter and darker than the background of 2 adjacent elements can emulate this. For Example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Untitled</title>
<style type="text/css">
div{background:#555;}
.top{border-bottom:#333 solid 1px;}
.bot{border-top:#777 solid 1px;}
</style>
</head>
<body>
<div class="top">this</div>
<div class="bot">andthis</div>
</body>
</html>

EDIT:

As a side note, switching light and dark in the example above will give you a slightly raised/embossed border effect.

查看更多
别忘想泡老子
3楼-- · 2019-02-02 01:26

Simply do the following:

.hr {
  opacity: 0.2;
  border-top: 1px solid #000;
  border-bottom: 1px solid #fff;
}

Play with opacity and colors to suit your design, It works on all backgrounds I think ;)

查看更多
登录 后发表回答