2
3

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 5 years have passed since last update.

cssで四隅にだけ囲み枠をつける方法

Last updated at Posted at 2019-11-06

「四つ角」というワードで検索するとなかなか情報が出てこない。
毎度忘れて検索しがちなので備忘録のためにまとめておく。
DEMO(codepen.io)


borderを擬似要素で隠すイメージ
スクリーンショット 2019-11-06 19.52.50.jpg

index.html
<div class="wrapper">
  <span>wrapper</span>
</div>
style.css

.wrapper {
  text-align: center;
  width: 100px;
  position: relative;
  border: solid 1px black;
  background-color: #fff;
}

.wrapper::before,
.wrapper::after {
  position: absolute;
  content: "";
  display: block;
  background-color: #fff;
}

.wrapper::before {
  top: -1px;
  bottom: -1px;
  left: 5px;
  right: 5px;
}

.wrapper::after {
  top: 5px;
  bottom: 5px;
  left: -1px;
  right: -1px;
}

.wrapper span {
  position: relative;
  z-index: 1;
}

参考:3 CSS techniques for border only in corners

2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?