<div class="wrap" id="totop">
<header id="header">
<nav>
<ul>
<li><a href="#section_01">section1</a></li>
<li><a href="#section_02">section2</a></li>
<li><a href="#section_03">section3</a></li>
</ul>
</nav>
</header>
<main>
<section id="section_01">
section1だよ〜
</section>
<section id="section_02">
section2だよ〜
</section>
<section id="section_03">
section3だよ〜
</section>
</main>
<a id="btn_pagetop" href="#totop">PAGE TOP</a>
</div>
html {
scroll-behavior: smooth; /* スムーススクロール */
}
section {
scroll-margin-top: 50px; /* スクロール位置をsectionの上に数値分空ける */
height: 500px;
padding: 60px 20px;
}
section:nth-child(even) {
background-color: #eee;
}
/* 以下はただの装飾 */
header {
background-color: #73c7ce;
position: fixed;
top: 0;
left: 0;
right: 0;
}
nav ul {
display: flex;
justify-content: center;
}
nav ul li a {
color: #fff;
display: flex;
align-items: center;
height: 50px;
text-decoration: none;
padding: 0 20px;
transition: 0.2s;
}
nav ul li a:hover {
background-color: #fff;
color: #73c7ce;
}
.wrap {
padding-top: 50px;
}
#btn_pagetop {
background-color: transparent;
border-radius: 50%;
color: #fff;
display: flex;
justify-content: center;
align-items: center;
text-decoration: none;
position: fixed;
bottom: 20px;
right: 20px;
width: 100px;
height: 100px;
transition: .3s;
}
#btn_pagetop::before,
#btn_pagetop::after {
content: "";
border-radius: 50%;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
#btn_pagetop::before {
background: #73c7ce;
z-index: -1;
transition: .3s;
}
#btn_pagetop::after {
border: 3px solid #73c7ce;
box-sizing: border-box;
}
#btn_pagetop:hover {
background-color: #fff;
color: #73c7ce;
}
#btn_pagetop:hover::before {
transform: scale(0);
opacity: 0;
}
//アンカー時のハッシュタグを消す
window.onhashchange = () => {
if (window.location.hash) {
window.history.replaceState(
null,
"",
window.location.pathname + window.location.search
);
}
};
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.