示例工程 11-positioning
11-positioning/demo-02-fixed-sticky/style.css
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
body {
margin: 0;
padding: 32px;
background: #f8fafc;
color: #0f172a;
font-family: system-ui, sans-serif;
line-height: 1.7;
}
h1 {
margin: 0 0 8px;
font-size: 26px;
}
.scroll {
max-height: 220px;
margin-top: 14px;
padding: 0 14px;
overflow-y: auto;
border: 1px solid #e2e8f0;
border-radius: 10px;
background: #ffffff;
}
.sticky {
position: sticky;
top: 0;
margin: 0;
padding: 10px 0;
background: #ffffff;
color: #2563eb;
font-size: 14px;
}
.scroll p {
margin: 0;
padding: 8px 0;
border-top: 1px solid #e2e8f0;
font-size: 13px;
}
.fixed {
position: fixed;
right: 18px;
bottom: 18px;
width: 56px;
height: 56px;
border: 0;
border-radius: 50%;
background: #0f172a;
color: #ffffff;
font-size: 11px;
}