表示デモ
実装コード
HTML
<div class="demo-wrap">
<button class="btn basic basic_op">Button Sample</button>
</div>
CSS
@charset "utf-8";
/* サイト共通設定 */
:root{
--primary-color: #03588C;
--primaty-opacity-color: 0.8;
}
html{
font-size: 62.5%;
}
.demo-wrap {
display: flex;
justify-content: center;
padding: 50px;
}
/* ボタン共通設定 */
.btn {
display:inline-block;
padding: 12px 30px;
font-weight: 600;
line-height: 1.3;
cursor: pointer;
border: 0;
font-size: 1.6rem;
text-decoration: none;
color: #ffffff;
transition: all .25s ease;
-webkit-tap-highlight-color: transparent;
}
.basic {
background: var(--primary-color);
}
/* 変化 */
.basic_op:hover, .basic_op:focus {
opacity: var(--primaty-opacity-color);
}
ポイント
hoverで半透明になるシンプルなボタン。
opacityの数値を0〜1で変更して不透明度を調整できる。
ボタンリンクにしたい場合は、<button>を<a>に置き換える。