Help us understand the problem. What is going on with this article?

CSSでテープを作る。

More than 3 years have passed since last update.

sample.png

<div class="tape">tape</div>
.tape{
  /* tape design */
  --jaggySize: 3px;
  --jaggyColor: rgba(255,0,0,.8);
  --tapeColor: rgba(255,0,0,.8);

  width: 70px; height: 30px;
  min-width: 60px;
  padding: 0 calc(var(--jaggySize) * 2);

  background:
    linear-gradient(+30deg, transparent 50%, var(--jaggyColor) 50%)
      left center / var(--jaggySize) var(--jaggySize) repeat-y,

    linear-gradient(-30deg, transparent 50%, var(--jaggyColor) 50%) 
      right center /  var(--jaggySize) var(--jaggySize) repeat-y,

    linear-gradient(to left, 
      transparent var(--jaggySize), var(--tapeColor) var(--jaggySize), 
      var(--tapeColor) calc(100% - var(--jaggySize)), transparent calc(100% - var(--jaggySize)));

}

テープを使ったデザイン

sample2.png

<div class="box">
  <h1>hello</h1>
  <div class="tape"></div>
</div>
/* 箱 */
.box{
  position: relative;

  width: 100px; height: 100px;
  margin: 50px;
  border: 2px solid black;
  text-align: center;
}

.tape{
  /* tape design */
  --jaggySize: 3px;
  --jaggyColor: rgba(255,0,0,.8);
  --tapeColor: rgba(255,0,0,.8);

  width: 70px; height: 30px;
  min-width: 60px;
  padding: 0 calc(var(--jaggySize) * 2);

  background:
    linear-gradient(+30deg, transparent 50%, var(--jaggyColor) 50%)
      left center / var(--jaggySize) var(--jaggySize) repeat-y,

    linear-gradient(-30deg, transparent 50%, var(--jaggyColor) 50%) 
      right center /  var(--jaggySize) var(--jaggySize) repeat-y,

    linear-gradient(to left, 
      transparent var(--jaggySize), var(--tapeColor) var(--jaggySize), 
      var(--tapeColor) calc(100% - var(--jaggySize)), transparent calc(100% - var(--jaggySize)));

  /* 位置・角度 */
  position: absolute;
  top: 0; left: 100%;
  transform: translate(-50%,-50%) rotate(45deg) translateY(25%);
}

補足

backgroundに3つlinear-gradient()があります。
これでテープを作っています。

指定順に1つ目・2つ目のlinear-gradientでテープ端のギザギザを表現、
3つ目はギザギザ用の空間の確保とテープの本体を作っています。

backgroundでbackground-imagebackground-positionbackground-sizebackground-repeat を指定しています。
position と sizeを指定する場合 /で区切って指定する必要があります。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away