1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ひとりCSSAdvent Calendar 2022

Day 21

clip-pathを使ってみる

Last updated at Posted at 2022-12-20

ひとりCSS Advent Calendar 2022 21日目です。

clip-path を使ってみます。

clip-path とは

シェイプが作れる。

よく使う三角

image.png

<div class="info-box">目立たせたいボックス</div>
.info-box {
  background: #fff;
  padding: 2em;
  position: relative;
}

.info-box::after {
  position: absolute;
  top: 0;
  right: 0;
  display: block;
  content: "";
  width: 32px;
  height: 32px;
  background: var(--color1);
  clip-path: polygon(0% 0%, 100% 0%, 100% 100%);
}

See the Pen object-fit by Beco (@becolomochi) on CodePen.

border-left border-top で実装していたやつも簡単に書き換えられる。良い

窓みたいなかたち

image.png

.img-box {
  width: 150px;
  height: 180px;
  background: url(https://0.gravatar.com/avatar/3c635ac67557f954b04d37a24254f436?size=360) no-repeat;
  background-size: cover;
  background-position: center;
  clip-path: path('M 0 200 L 0,75 A 5,5 0,0,1 150,75 L 200 200 z');
}

See the Pen clip-path by Beco (@becolomochi) on CodePen.

パス指定さえすれば自在に作れるの楽しい。

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?