如何创建邮票边框?

Ma9*_*9ic 4 css css-shapes

我希望div看起来像这样:

在此输入图像描述

但是只想使用CSS,我将如何创建这样的形状呢?

我是否为顶部和底部创建自定义边框?

Per*_*ijn 6

如果您只想在图像的顶部和底部有边框,您可以使用伪元素来创建它。

邮票图片

.stamp {
  margin-top: 50px;
  margin-left: 50px;
  position: relative;
  width: 500px;
  height: 300px;
  background: #bbb;
  -webkit-filter: drop-shadow(3px 3px 1px black);
  filter: drop-shadow(0px 0px 5px white);
}
.stamp:before {
  position: absolute;
  top: -20px;
  display: block;
  content: "";
  background: radial-gradient(circle, transparent 15px, #bbb 16px);
  background-size: 50px 40px;
  background-position: -20px -20px;
  width: 100%;
  height: 40px;
  z-index: -1;
}
.stamp:after {
  position: absolute;
  bottom: -20px;
  content: "";
  display: block;
  background: radial-gradient(circle, transparent 15px, #bbb 16px);
  background-size: 50px 40px;
  background-position: -20px -20px;
  width: 100%;
  height: 40px;
  z-index: -1;
}
body {
  margin: 0;
  background-color: #333;
}
Run Code Online (Sandbox Code Playgroud)
<div class="stamp">
</div>
Run Code Online (Sandbox Code Playgroud)


iCo*_*ode 5

您可以在这里查看代码,它完全符合您的要求:http://codepen.io/orhanveli/pen/tbGJL

来自网站的代码:

HTML

<!-- Lets create a CSS3 stamp -->
<div class="stamp">
    <!-- the image -->
    <img src="http://thecodeplayer.com/uploads/media/css3logo.png" />
</div>
Run Code Online (Sandbox Code Playgroud)

CSS

*{margin: 0; padding: 0;}

body {
    background: #B1d202;
    padding: 100px;
    text-align: center;
}

.stamp {
    width: 280px;
    height: 180px;
    display: inline-block;
    padding: 10px;
    background: white;
    position: relative;
    -webkit-filter: drop-shadow(0px 0px 10px rgba(0,0,0,0.5));
    /*The stamp cutout will be created using crisp radial gradients*/
    background: radial-gradient(
        transparent 0px, 
        transparent 4px, 
        white 4px,
        white
    );

    /*reducing the gradient size*/
    background-size: 20px 20px;
    /*Offset to move the holes to the edge*/
    background-position: -10px -10px;
}
.stamp:after {
    content: '';
    position: absolute;
    /*We can shrink the pseudo element here to hide the shadow edges*/
    left: 5px; top: 5px; right: 5px; bottom: 5px;
    /*Shadow - doesn't look good because of the stamp cutout. We can still move this into another pseudo element behind the .stamp main element*/

  /*box-shadow: 0 0 20px 1px rgba(0, 0, 0, 0.5);*/
    /*pushing it back*/
    z-index: -1;
}
/*Some text*/
.stamp:before {
    content: 'CSS3';
    position: absolute;
    bottom: 0; left: 0;
    font: bold 24px arial;
    color: white;
    opacity: 0.75;
    line-height: 100%;
    padding: 20px;
}
.stamp img {

}
Run Code Online (Sandbox Code Playgroud)