设置 HTML 项目结构
在这一步中,你将为我们固定定位布局的演示创建项目结构。我们将在 ~/project
目录下设置一个简单的 HTML 项目,作为我们 CSS 定位练习的基础。
首先,导航到项目目录并创建必要的文件:
cd ~/project
mkdir fixed-positioning-demo
cd fixed-positioning-demo
现在,创建基本的 HTML 文件结构:
touch index.html
touch styles.css
打开 index.html
文件并添加以下基本 HTML 结构:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Fixed Positioning Layout Demo</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div class="content">
<h1>Fixed Positioning Layout</h1>
<p>This is a sample page to demonstrate fixed positioning in CSS.</p>
<!-- We'll add more content in subsequent steps -->
</div>
</body>
</html>
创建一个基本的 CSS 文件 styles.css
,并添加一些初始样式:
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 0;
}
.content {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
示例输出结构:
~/project/fixed-positioning-demo/
├── index.html
└── styles.css
此设置提供了一个干净、简单的项目结构,我们将在后续步骤中在此基础上演示固定定位技术。