<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Position Sticky Example</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="header">固定的標題欄</div>
<div class="section">
<h2>Section 1</h2>
<p>這是一個段落內容,用來展示滾動效果...</p>
</div>
<div class="section">
<h2>Section 2</h2>
<p>這是一個段落內容,用來展示滾動效果...</p>
</div>
<div class="section">
<h2>Section 3</h2>
<p>這是一個段落內容,用來展示滾動效果...</p>
</div>
<div class="section">
<h2>Section 4</h2>
<p>這是一個段落內容,用來展示滾動效果...</p>
</div>
</body>
</html>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.header {
position: sticky;
top: 0;
background-color: #4CAF50; /* 綠色背景 */
color: white;
padding: 15px;
font-size: 24px;
text-align: center;
border: 2px solid #388E3C; /* 深綠色邊框 */
}
.section {
padding: 20px;
height: 800px;
background-color: #f0f0f0; /* 淺灰色背景 */
border: 1px solid #ccc; /* 灰色邊框 */
margin-bottom: 20px;
}
.section:nth-child(odd) {
background-color: #e0e0e0; /* 交替的更深灰背景 */
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.