Как сделать зазубренный край элемента как у кассового чека?

Как сделать зазубренный край элемента как у кассового чека? С такой же угловатой верхней и нижней стороной.

Как можно сделать такой край с зазубринами с помощью CSS?


Ответы (3 шт):

Автор решения: ArtGrek13

https://atuin.ru/blog/zigzagoobraznyj-bordyur-na-css/

<html>

<head>
  <style>
    .zig-zag {
      /* белый прямоугольник */
      position: absolute;
      left: 10%;
      width: 200px;
      top: 10%;
      height: 400px;
      background-color: white;
      text-align: center;
    }
    
    .zig-zag:before {
      /* верхний зиг-заг */
      position: absolute;
      left: 0%;
      width: 200px;
      top: -32px;
      height: 32px;
      content: "";
      background: linear-gradient(-45deg, blue 16px, transparent 0), linear-gradient(45deg, blue 16px, transparent 0);
      background-repeat: repeat-x;
      background-position: left top;
      background-size: 4px;
      /* размер зубцов */
      background-color: green;
    }
    
    .zig-zag:after {
      /* нижний зиг-заг */
      position: absolute;
      left: 0%;
      width: 200px;
      top: 400px;
      height: 32px;
      content: "";
      background: linear-gradient(-45deg, transparent 8px, yellow 0), linear-gradient(45deg, transparent 8px, yellow 0);
      background-repeat: repeat-x;
      background-position: left bottom;
      background-size: 4px;
      /* размер зубцов */
      background-color: red;
    }
  </style>
</head>

<body style="background-color: black;">
  <div class="zig-zag">Кассовый чек</div>
</body>

</html>

→ Ссылка
Автор решения: Stranger in the Q

Вот, на css градиентах:

body {
  background: black;
}

div {
  padding: 5px;
  background:
    linear-gradient(-45deg, #0000 6px, #fff 7px),
    linear-gradient( 45deg, #0000 6px, #fff 7px),
    linear-gradient(-45deg, #fff calc(100% - 7px), #0000 calc(100% - 8px)),
    linear-gradient( 45deg, #fff calc(100% - 7px), #0000 calc(100% - 8px));
  background-size: 10px 50%;
  background-position: 0 100%, 0 100%, 0 0, 0 0;
  background-repeat: repeat-x;
}
<div>123456</div>

→ Ссылка
Автор решения: MaximLensky

Сделал руками

<svg width="210px" viewBox="0 0 210 297" xmlns="http://www.w3.org/2000/svg">
  <defs>
    <style>
      .fo h5{
        font-size: 12px;
        margin-left: 5px;
      }
      .fo li{
        display: flex;
        justify-content: space-between;
        border-bottom: 1px dotted #000;
        font-size: 12px;
        margin-top: 6px;
      }
      #res{
        font-size: 14px;
      }
    </style>
  </defs>
 <path d="M0,20 210,20 210,297 0,297z" fill="#e2e3de"/>
 <path d="M0,20 210,20" fill="none" stroke="#e2e3de" stroke-dasharray="3 3" stroke-width="3"/>
  <text x="100" y="100" text-anchor="middle">Фискальный чек</text>
  
    <foreignObject x="20" y="100" width="170" height="160" class="fo">
      <h5>Магазин "Рога и Капыта"</h5>
      <li>
        <span>Хлеб</span>
        <span>100 Руб</span>
      </li>
        <li>
        <span>Водка</span>
        <span>800 Руб</span>
      </li>
        <li>
        <span>Сало</span>
        <span>213 Руб</span>
      </li>
   </foreignObject>
  
  <text x="100" y="270" id="res">Итого: 1013руб</text>
</svg>

let price = document.querySelectorAll(".price");
let res = document.querySelector(".res");
let ocum = [],
  summ = 0;

price.forEach(function(el) {
  ocum.push(+el.innerHTML);
  el.append(" p");
})


let reducer = ocum.reduce(function(a, b) {
  return a + b;
})

res.innerHTML = `Итого  ${reducer}  руб`;
body{
  background: #fafafa;
}

.check{
  position: relative;
  margin: 30px;
  width: 300px;
  min-height: 250px;
  background: #e2e3de;
  padding: 4px 10px;
  box-shadow: 0 0 50px rgba(0,0,0,0.1);
}

.check svg{
  position: absolute;
  top: -3px;
  left: 2px;
  width: 100%;
}

.info{
  text-align: center;
}

.info span{
  font-size: 12px;
  line-height: 2px;
  margin: 0;
}

h4{
  text-align: center;
}

.check ul{
  margin: 0;
  padding: 0;
}

.check ul li{
  display: flex;
  justify-content: space-between;
  margin: 10px 0;
  border-bottom: 1px dotted #000;
}

.res{
  text-align: right;
  padding: 10px 20px;
}
<div class="check">
  <svg width="210px" viewBox="0 0 210 5" xmlns="http://www.w3.org/2000/svg">
   <path d="M0,0 210,0" fill="none" stroke="#e2e3de" stroke-dasharray="3 3" stroke-width="10"/>
  </svg>

  <div class="info">
    <span>Магазин "Рога и Капыта"</span>
    <span>Юридический адресс: Неизвестный край, г.Чепухово 34</span>
  </div>
  <h4>Фискальный чек</h4>
  <ul>
    <li><span>Колбаса</span><span class="price">600</span></li>
    <li><span>Сыр</span><span class="price">560</span></li>
    <li><span>Хлеб</span><span class="price">80</span></li>
    <li><span>Томаты</span><span class="price">100</span></li>
    <li><span>Каша Боярин</span><span class="price">80</span></li>
    <li><span>Сухой корм</span><span class="price">40</span></li>
    <li><span>Макароны</span><span class="price">100</span></li>
    <li><span>Стиральный порошок</span><span class="price">120</span></li>
    <li><span>Томатная паста</span><span class="price">50</span></li>
    <li><span>Туалетная бумага</span><span class="price">20</span></li>
  </ul>

  <p class="res">Какая то сумма</p>
</div>

→ Ссылка