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

CSS3 ポリゴンボタン

More than 3 years have passed since last update.

CSS3だけでポリゴンボタンを作ってみました。

codepenでのdemo
http://codepen.io/inoma/pen/ZGYGbd

CSS

CSS
a,
:after{
  text-decoration:none;
  -webkit-transition: all 0.2s;
  -moz-transition: all 0.2s;
  transition: all 0.2s;
}
section{
  clear:both;
}
div{
  float:left;
  margin:0 30px 30px 0;
}

/* sample1 */
.sample1 a{
  width:100px;
  height:100px;
  background-color:#ED6464;
  text-align: center;
  color: #fff;
  font-size: 5rem;
  line-height:100px;
  display:block;
  overflow:hidden;
  position: relative;
  z-index:1;
}
.sample1 a:after{
  width: 0px;
    height: 0px;
  content:'';
    border: 50px solid transparent;
    border-bottom: 50px solid #C25757;
  border-right: 50px solid #C25757;
  position: absolute;
  bottom:0;
  right:0;
  z-index:-1;
}
.sample1 a:hover{
  background-color:#e2e2e2;
  color:#ED6464;
}
.sample1 a:hover:after{
  border: 80px solid transparent;
}
.porigon1 a:after{
    border: 50px solid transparent;
    border-bottom: 50px solid #9A4747;
  border-right: 50px solid #C25757;
  border-left: 50px solid #C25757;
}

/* sample2 */
.sample2 a{
  width:100px;
  height:100px;
  background-color:#38D3EB;
  border: 2px solid #fff;
  box-sizing: border-box;
  text-align: center;
  color: #fff;
  font-size: 5rem;
  line-height:100px;
  display:block;
  overflow:hidden;
  position: relative;
  z-index:1;
}
.sample2 a:after{
  width: 0px;
    height: 0px;
  content:'';
    border: 50px solid transparent;
    border-bottom: 50px solid #2EADC0;
  border-right: 50px solid #2EADC0;
  position: absolute;
  bottom:0;
  right:0;
  z-index:-1;
}
.sample2 a:hover{
  background-color:#fff;
  color:#38D3EB;
  border: 2px solid #38D3EB;
}
.sample2 a:hover:after{
  border: 80px solid transparent;
}
.porigon2 a:after{
    border: 50px solid transparent;
    border-bottom: 50px solid #2792A2;
  border-right: 50px solid #2EADC0;
  border-left: 50px solid #2EADC0;
}

/* sample3 */
.sample3 a{
  width:200px;
  height:100px;
  background-color:#F3D735;
  text-align: center;
  color: #fff;
  font-size: 5rem;
  line-height:100px;
  display:block;
  overflow:hidden;
  position: relative;
  z-index:1;
}
.sample3 a:after{
  width: 0px;
    height: 0px;
  content:'';
    border: 100px solid transparent;
    border-bottom: 0px solid #D4BB2F;
  border-right: 200px solid #D4BB2F;
  position: absolute;
  bottom:0;
  right:0;
  z-index:-1;
}
.sample3 a:hover:after{
  border: 100px solid transparent;
}
.porigon3 a:after{
    border: 50px solid transparent;
    border-bottom: 50px solid #B8A328;
  border-right: 100px solid #D4BB2F;
  border-left: 100px solid #D4BB2F;
}

/* sample4 */
.sample4 a{
  width:100px;
  height:200px;
  background-color:#7BD84C;
  text-align: center;
  color: #fff;
  font-size: 5rem;
  line-height:200px;
  display:block;
  overflow:hidden;
  position: relative;
  z-index:1;
}
.sample4 a:after{
  width: 0px;
    height: 0px;
  content:'';
    border: 200px solid transparent;
    border-bottom: 0px solid #6BBA43;
  border-right: 100px solid #6BBA43;
  position: absolute;
  bottom:0;
  right:0;
  z-index:-1;
}
.sample4 a:hover{
  background-color:#6BBA43;
}
.sample4 a:hover:after{
  border: 0px solid transparent;
}
.porigon4 a:after{
    border: 100px solid transparent;
    border-bottom: 100px solid #599C38;
  border-right: 50px solid #6BBA43;
  border-left: 50px solid #6BBA43;
}

HTML

HTML
<section>
 <div class="sample1"><a href="#">A</a></div>
 <div class="sample1 porigon1"><a href="#">A</a></div>
</section>

<section>
 <div class="sample2"><a href="#">B</a></div>
 <div class="sample2 porigon2"><a href="#">B</a></div>
</section>

<section>
 <div class="sample3"><a href="#">C</a></div>
 <div class="sample3 porigon3"><a href="#">C</a></div>
</section>

<section>
 <div class="sample4"><a href="#">D</a></div>
 <div class="sample4 porigon4"><a href="#">D</a></div>
</section>
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
Comments
No 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
ユーザーは見つかりませんでした