纯css实现右下角按钮点击滚动返回页面顶部效果代码

代码语言:html

所属分类:加载滚动

代码描述:纯css实现右下角按钮点击滚动返回页面顶部效果代码,无js代码,纯css代码实现这个效果。

代码标签: css 右下角 按钮 点击 滚动 返回 页面 顶部

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开


<!DOCTYPE html>
<html lang="en" >

<head>

 
<meta charset="UTF-8">
 

 
 
 
<style>
body
{
 
display: grid;
 
grid-template-columns: 1fr 0px;
 
font-family: system-ui, sans-serif;
 
background: #eee;
}
.top {
 
--offset: 100px; /* control when the button appear */
 
 
position: sticky;
 
bottom: 20px;      
 
margin-right: 10px;
 
place-self: end;
 
margin-top: calc(100vh + var(--offset));

 
width: 60px;
 
aspect-ratio: 1;
 
background: #ff8b24;
 
border-radius: 10px;
 
font-size: 0;
}
.top:before {
 
content: "";
 
position: absolute;
 
inset: 30%;
 
transform: translateY(20%) rotate(-45deg);
 
border-top: 5px solid #fff;
 
border-right: 5px solid #fff;
}
h1
{
 
font-size: 3rem;
}
p
{
 
font-size: 1.5rem;
 
text-align:justify;
}
body
> div {
 
margin-inline: max(3px,50% - 800px/2);
}

/* remove the below if you don't want smooth scrolling */
html
,
body
{
       
scroll-behavior: smooth;
}
</style>



</head>


 
<body>
 
<div>
   
<!-- your content goes here  -->
   
<h1>Main Title</h1>
   
<p>
      Bear claw gummi bears danish ice cream halvah cotton candy pastry choc.........完整代码请登录后点击上方下载按钮下载查看

网友评论0