用阴影堆叠两个边框?

时间:2012-06-05 19:45:15

标签: html css css3 web dropshadow

如何围绕另一个边框包裹边框并让它们都使用插入阴影(如图片框中的双重遮罩)?

3 个答案:

答案 0 :(得分:1)

Here are my fiddle's on the topic


选项1)

您可以使用Pseudo Classes来完成此任务

HTML

<span class="doubleMatt">
    <img src="http://lorempixel.com/400/200/" />
</span>

CSS

span,img{padding:0;margin:0;border:0;}
.doubleMatt{
    position:relative;
    display:inline-block;
    font-size:0;
    line-height:0;
}

.doubleMatt:after{
    position:absolute;
    top:1px;
    left:1px;
    bottom:1px;
    right:1px;
    border:4px solid rgba(255,255,255,0.5);
    outline:1px solid rgba(0,0,0,0.2);
    content:" ";
}​

选项2)

你可以使用一些基本的(一维)善良

CSS

.basicMatt {
    background:#222;
    padding:3px;
    border:3px solid #666;
}

HTML

<img class="basicMatt" src="http://www.lorempixel.com/400/200/" />

选项3)

你可以使用大纲

CSS

.outlinedMatt{
    background:#fff;
    padding:8px;
    border:3px solid #222;
    outline:3px solid #666;
    margin:3px;
}

HTML

<img class="outlinedMatt" src="http://www.lorempixel.com/400/200" />

答案 1 :(得分:1)

你可以嵌套div,如 - http://jsfiddle.net/nG4Td/2/

所示
<div class="border">
  <div class="border2">
    <p>hello world</p>
  </div>
</div>

CSS

.border{
  border: 5px inset black;
  background:#ccc;
  width:200px;
  height:200px;
  padding:20px;    
}
.border2{
  border: 5px inset black;
  background:#eee;
  width:150px;
  height:150px;
  padding:20px;    
 }`

答案 2 :(得分:1)

您可以使用:before and :after pseudo-elements完成此操作。在答案结束时查看jsFiddle演示。

HTML

<div class="frame"><img src="../img/logo.png"></div>

CSS

.frame {
    display:inline-block;
    position:relative;
    margin:20px;
    z-index:5;
    padding:10px;
    background:#376b90;
}
.frame:before {
    position:absolute;
    content:".";
    display:block;
    font-size:0;
    color:transparent;
    /* Change left, right, top, bottom, and box-shadow to position */
    left:0;
    top:0;
    right:0;
    bottom:0;
    box-shadow:inset 0 0 3px 2px black;
}
.frame:after {
    position:absolute;
    content:".";
    display:block;
    font-size:0;
    color:transparent;
    /* Change left, right, top, bottom, and box-shadow to position */
    left:5px;
    top:5px;
    right:5px;
    bottom:5px;
    box-shadow:inset 0 0 3px 2px black;
}

使用示例