option 1
Using outline
and outline-offset
the outline works as an embroidery and the offset puts that draw in a little, simulating the effect, the size of the border is controlled by outline-width
and outline-color
color. It is also responsive and does not lose resolution.
Browser support: link
Mozilla Documentation: link
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 mentioned by @bacco another option would be using radial-gradient, so you do not need to use an image as a reference for the borders.
The positives , no image involved, no img request on the server, no resolution problem if you want to change the size and it is easy to change the color any time I want
Negative Points , is not as flexible as border-image
in width x height , and is not as practical as maintenance of the code.
Follow the example. Notice that it's just a div that is the seal. it uses two pseudo elements. one with the pattern of the polka dots, and another to make the content 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: link
Mozilla's radial-gradient documentation: link