option 1
Using outline
and outline-offset
Outline works like an embroidery and the offset puts this borar a little inward, simulating the effect, the size of the border is controlled by the outline-width
and the outline-color
color. Also it is very responsive and does not lose resolution.
Browser support: https://caniuse.com/#feat=Outline
Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/CSS/outline-offset
div {
width: 30%;
height: 40%;
position: relative;
background-color: black;
outline-style: dotted;
outline-width: 2em;
outline-color: #fff;
outline-offset: -1em;
float: left;
margin: 30px;
}
div > section {
position: relative;
z-index: 2;
box-sizing: border-box;
padding: 40px;
display: block;
color: #fff;
}
<div>
<section>
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Fuga labore illo rem ut. Iusto, temporibus laboriosam? Odio sapiente veritatis similique.
</section>
</div>
<div style="outline-color: #f00; width: 300px; height: 200px">
<section>
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Fuga labore illo rem ut. Iusto, temporibus laboriosam? Odio sapiente veritatis similique.
</section>
</div>
OBS: Does not work in IE :(
Option 2
In addition to the option quoted by @Acco another option would be using radial-gradient, so you don’t need to use an image as a border reference.
The positive points, no image involved, no img request on the server, no resolution problem if you want to change the size and it’s easy to change the color the time I want.
Negatives, is not as flexible as the border-image
in the category width x height, and is not as practical as code maintenance.
Follow the example. Note that it is only a div that is the seal. it uses two pseudo elements. one with the Pattern of the balls, and another to make the contents box.
div {
width: 300px;
height: 400px;
position: relative;
/* border: 1px solid; */
background-color: black;
}
div::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
/* background-color: aquamarine; */
background-image: radial-gradient(circle, #fff 0%, #fff 49%, transparent 51%, transparent 100%);
background-size: 50px 50px;
background-position: -25px -25px;
}
div::after {
content: "";
position: absolute;
top: 0;
left: 0;
width: calc(300px - 50px);
height: calc(400px - 50px);
background-color: #fff;
right: 0;
bottom: 0;
margin: auto;
}
div > section {
position: relative;
z-index: 2;
box-sizing: border-box;
padding: 40px;
display: block;
}
<div>
<section>
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Fuga labore illo rem ut. Iusto, temporibus laboriosam? Odio sapiente veritatis similique.
</section>
</div>
Browser support from IE10: https://caniuse.com/#feat=css-gradients
Mozilla radial gradient documentation: https://developer.mozilla.org/en-US/docs/Web/CSS/radial-gradient
https://stackoverflow.com/questions/21044525/how-can-i-create-a-postage-stamp-border
– David