かもメモ

自分の落ちた落とし穴に何度も落ちる人のメモ帳

CSS フォームとかで使えるステップバー作ってみた。

フォームのイマココ!とか表示できるシンプルなステップバーをCSSだけで作ってみた。
当然のようにIE8とかは無視してます。ご了承下さい。

SAMPLE

See the Pen SIMPLE FORM STEP BAR by Chaika (@chaika-design) on CodePen.

SIMPLE FORM STEP BAR

HTML

<ol class="stepBar step3">
  <li class="step current">STEP1</li>
  <li class="step">STEP2</li>
  <li class="step">STEP3</li>
</ol>

Compass (SCSS)

.stepBar {
  position: relative;
  list-style: none;
  margin: 0 0 1em;
  padding: 0;
  text-align: center;
  width: 100%;
  @include clearfix;
  .step {
    position: relative;
    float: left;
    display: inline-block;
    line-height: 40px;
    padding: 0 40px 0 20px;
    background-color: #eee;
    @include box-sizing(border-box);
    &:before,
    &:after {
      position: absolute;
      left: -15px;
      display: block;
      content: '';
      background-color: #eee;
      border-left: 4px solid #FFF;
      width: 20px;
      height: 20px;
    }
    &:after {
      top: 0;
      @include transform(skew(30deg));
    }
    &:before {
      bottom: 0;
      @include transform(skew(-30deg));
    }
    &:first-child {
      @include border-left-radius(4px);
      &:before,
      &:after {
        content: none;
      }
    }
    &:last-child {
      @include border-right-radius(4px);
    }
    &.current {
      color: #FFF;
      background-color: $colGreen;
      &:before,
      &:after {
        background-color: $colGreen;
      }
    }
  }
  &.step2 {
    .step {
      width: 50%;
    }
  }
  &.step3 {
    .step {
      width: 33.333%;
    }
  }
  &.step4 {
    .step {
      width: 25%;
    }
  }
  &.step5 {
    .step {
      width: 20%;
    }
  }
}

CSS

コンパイルされたCSS

.stepBar {
  position: relative;
  list-style: none;
  margin: 0 0 1em;
  padding: 0;
  text-align: center;
  width: 100%;
  overflow: hidden;
  *zoom: 1;
}
.stepBar .step {
  position: relative;
  float: left;
  display: inline-block;
  line-height: 40px;
  padding: 0 40px 0 20px;
  background-color: #eee;
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}
.stepBar .step:before, .stepBar .step:after {
  position: absolute;
  left: -15px;
  display: block;
  content: '';
  background-color: #eee;
  border-left: 4px solid #FFF;
  width: 20px;
  height: 20px;
}
.stepBar .step:after {
  top: 0;
  -moz-transform: skew(30deg);
  -ms-transform: skew(30deg);
  -webkit-transform: skew(30deg);
  transform: skew(30deg);
}
.stepBar .step:before {
  bottom: 0;
  -moz-transform: skew(-30deg);
  -ms-transform: skew(-30deg);
  -webkit-transform: skew(-30deg);
  transform: skew(-30deg);
}
.stepBar .step:first-child {
  -moz-border-radius-topleft: 4px;
  -webkit-border-top-left-radius: 4px;
  border-top-left-radius: 4px;
  -moz-border-radius-bottomleft: 4px;
  -webkit-border-bottom-left-radius: 4px;
  border-bottom-left-radius: 4px;
}
.stepBar .step:first-child:before, .stepBar .step:first-child:after {
  content: none;
}
.stepBar .step:last-child {
  -moz-border-radius-topright: 4px;
  -webkit-border-top-right-radius: 4px;
  border-top-right-radius: 4px;
  -moz-border-radius-bottomright: 4px;
  -webkit-border-bottom-right-radius: 4px;
  border-bottom-right-radius: 4px;
}
.stepBar .step.current {
  color: #FFF;
  background-color: #26bfa1;
}
.stepBar .step.current:before, .stepBar .step.current:after {
  background-color: #26bfa1;
}
.stepBar.step2 .step {
  width: 50%;
}
.stepBar.step3 .step {
  width: 33.333%;
}
.stepBar.step4 .step {
  width: 25%;
}
.stepBar.step5 .step {
  width: 20%;
}

ステップ数に応じて.step{N}みたいなクラスを作って幅を指定して上げれば多分オケオケオッケー☆
ステップクリックで移動とかなら:hoverの時にbackground-colorを変更すればそれっぽくなると思います。


[参考]