HTMLの書き方
head終了タグ直前に自作のCSSを読み込みます。
<link rel="stylesheet" type="text/css" href="css/5-3-8.css">
body内のテキストナビゲーションを表示させたい場所に以下のHTMLを記載します。
<ul class="gnavi">
<li class="current"><a href="#">Home</a></li><!--現在地にはcurrentクラスを付ける-->
<li><a href="#">About</a></li>
<li><a href="#">Service</a></li>
<li><a href="#">Contact</a></li>
</ul>
CSSの書き方
/*==================================================
共通 横並びのための設定
===================================*/
.gnavi{
display: flex;
flex-wrap: wrap;/*スマホ表示折り返し用なのでPCのみなら不要*/
margin:0 0 50px 0;
list-style: none;
}
.gnavi li a{
display: block;
padding:10px 30px;
text-decoration: none;
color: #333;
}
.gnavi li{
margin-bottom:20px;
}
/*==================================================
5-3-8 円が線に変化
===================================*/
.gnavi li a{
/*円の基点とするためrelativeを指定*/
position: relative;
}
.gnavi li.current a,
.gnavi li a:hover{
color:#0481A2;
}
.gnavi li a::after {
content: '';
/*絶対配置で線の位置を決める*/
position: absolute;
bottom: 0;
left: 0;
/*線になる丸の形状*/
width: 100%;
height: 5px;
border-radius: 50%;
background:#0481A2;
/*アニメーションの指定*/
transition: all .3s;
transform: scale(0.04, 1);/*X方向0.04、Y方向1*/
transform-origin:center bottom;/*中央下部基点*/
}
/*現在地とhoverの設定*/
.gnavi li.current a::after,
.gnavi li a:hover::after {
height: 2px;/*縦幅を変化*/
border-radius: 0;/*丸みをなくす*/
transform: scale(0.8, 1);/*X方向0.8、Y方向1にスケール拡大*/
}