Is it possible to create a type element with a CSS Stamp?

5

What is the best way or best way to build a CSS-like letterhead element? (at the moment I did not want to have to use SVG)

I'm trying to build this form with HTML / CSS and the option I have at the moment does not please me.

TheoptionIfoundisthisbelow.ButIdonotlikeit,becauseIwouldneedalotof%stofinishtheform,andifIwantedtochangethesizeoftheStampwouldbeabitcomplicatedandnotveryapplicable.

.selo {
	width: 300px;
	height: 400px;
	position: relative;
  background-color: black;
  overflow: hidden;
}
.topo {
  height: 50px;
  width: 100%;
  display: flex;
  position: relative;
  transform: translateY(-50%);
}
.bola {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background-color: #fff;
  margin: 0 auto;
}
<div class="selo">
  <div class="topo">
    <div class="bola"></div>
    <div class="bola"></div>
    <div class="bola"></div>
    <div class="bola"></div>
  </div>
</div>

With CSS and HTML how to construct this element in a practical way with less code?

    
asked by anonymous 30.08.2018 / 19:32

3 answers

15

The property border-image is great for this.

It allows you to use a technique called 9 patch, which cuts the quad image.

border-image: url(   ) 20 20 20 20 round round;

/*         imagem -^   ^---- medidas ----^ ^-metodo-^      */

Demonstrating:

Our reference image:

Clickruntoseeapplied:

.selo {
    margin:10px;
    padding:10px;
    display:inline-block;
    /* O que nos interessa é o border apenas, nas linhas abaixo. acima é só pro demo */
    border:20px solid transparent;
    border-image: url(https://i.stack.imgur.com/K5VX5.png) 20 20 20 20 round round;
}
<div class="selo">
   Chegou carta!<br>
   C O R R E I O S
</div>

<div class="selo">
   ... e outra carta, um bocado maior.<br>
   <br>
   Quem sabe é um cheque bem gordo.
</div>

Documentation:

  

link

Compatibility:

  

link


Viewing what happened:

To better understand the effect, a colorful version of the image follows:

Tofacilitatethecalculation,inbothcasesweuseda60pxwideimage,sothateachquadrantwas20px:

In border-image we will specify these 20px as distance to the top, right side, bottom and left side. The rest will be "accommodated" to fill in the drawing.

The three forms of filling are:

  • stretch - it "stretches" the middle pieces until it fills the space;

  • repeat - instead of "stretching", the middle pieces are used as repetitive texture;

  • round - tries to make a repetitive texture, but gives a "rounding" by rounding the measurements so that no splices appear.

Note that in our case, I used 20 in all quadrants just to facilitate. Nothing prevents the image from having different proportions on each side.

.selo {
    margin:10px; 
    padding:10px; 
    border:20px solid transparent;
    border-image: url(https://i.stack.imgur.com/kvUY1.png) 20 20 20 20 round round;
}
<div class="selo">
   Chegou carta!<br>
   
   C O R R E I O S
</div>
    
30.08.2018 / 19:45
3

I am not a double post, but there is a lot of information in the other - note that I posted as community wiki not to abuse punctuation
you know, posts marked as Community wiki, even if voted well, do not give points to the author.


Using borders

Just to complete the post, it follows a version with borders and pseudo-elements:

Basically it is a white border with dots, on a solid black border:

.selo {
  position:relative;
  display:inline-block;
  padding:20px;
  border:10px dotted #fff;
}

.selo:after {
  content:'';
  position:absolute; box-sizing: border-box;
  top:-5px; right:-5px; bottom: -5px; left:-5px; 
  border:10px solid #000;
  z-index: -1;
}
<div class="selo">
  Carta 1<br>
  00000-000 - São Paulo - SP
</div>

<div class="selo">
  Cartinha 2
</div>
    
30.08.2018 / 21:32
2

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

    
30.08.2018 / 20:53