HTMLの書き方
head終了タグ直前に自作のCSSを読み込みます。
<link rel="stylesheet" type="text/css" href="css/7-1-35.css">
body内のボタンを表示させたい場所に以下のHTMLを記載します。
<a href="#" class="btnlinestretches3"><span>7-1-35 下線が伸びて背景に変わる</span></a>
CSSの書き方
/*== 下線が伸びて背景に変わる */
.btnlinestretches3{
/*線の基点とするためrelativeを指定*/
position:relative;
/*ボタンの形状*/
color:#333;
padding: 10px 30px;
display:inline-block;
text-decoration: none;
outline: none;
}
/*テキストの設定*/
.btnlinestretches3 span{
/*テキストを前面に出すためz-indexの値を高く設定*/
position:relative;
z-index: 2;
}
.btnlinestretches3:hover span{
color: #fff;
}
/*線の設定*/
.btnlinestretches3::after {
content:'';
/*絶対配置で線の位置を決める*/
position:absolute;
z-index:1;
bottom:0;
left:0;
/*線の形状*/
background:#333;
width:100%;
height:3px;
/*アニメーションの指定*/
transition:all 0.3s ease-in-out;
}
/*線が伸びて背景に*/
.btnlinestretches3:hover::after {
height:100%;
}