Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
22
Help us understand the problem. What is going on with this article?
@junya

CSS 枠線アニメーションを作る

More than 5 years have passed since last update.

sampleGif.gif

マウスが乗ると枠線がアニメーションして出てくる

html


<div id="wrap">
<div class="box"></div>
</div>

CSS


#wrap{
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #000;
}

.box{
  position: relative;
  background: red;
  width: 300px;
  height: 300px;
}

.box:before,.box:after{
  content: '';
  position: absolute;
  height: 3px;
  width: 3px;
  background: #fff;
  transition: width 0.3s,height 0.3s;
}

.box:before{
  top: 0;
  right: 0;
  box-shadow: -297px 0 0 0 #fff; /* 配置位置:親要素の大きさ(300) - 自身の大きさ(3)  */
  opacity: 0;
}

.box:after{
  bottom: 0;
  right: 0;
  box-shadow: 0 -297px 0 0 #fff; /* 配置位置:親要素の大きさ(300) - 自身の大きさ(3)  */
  opacity: 0;
}

.box:hover:before{
  opacity: 1;
  height: 100%;
}

.box:hover:after{
  opacity: 1;
  width: 100%;
}

22
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  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
junya

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
22
Help us understand the problem. What is going on with this article?