1. 基本样式设置
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Example</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
color: #333;
margin: 0;
padding: 0;
}
h1 {
color: #008080;
}
p {
line-height: 1.5;
}
</style>
</head>
<body>
<h1>Hello, CSS!</h1>
<p>This is a simple CSS example.</p>
</body>
</html>
2. 盒模型和布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Box Model Example</title>
<style>
.box {
width: 200px;
height: 100px;
background-color: #3498db;
margin: 20px;
padding: 10px;
border: 2px solid #2980b9;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<div class="box">
<p>This is a box with some content.</p>
</div>
</body>
</html>
3. 媒体查询
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Media Query Example</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
}
@media screen and (max-width: 600px) {
body {
background-color: #ecf0f1;
}
}
@media screen and (min-width: 601px) {
body {
background-color: #3498db;
color: #fff;
}
}
</style>
</head>
<body>
<h1>Responsive Design with Media Query</h1>
<p>This text and background color will change based on the screen width.</p>
</body>
</html>
这些例子涵盖了一些基本的CSS概念,包括样式设置、盒模型和布局、媒体查询等。你可以根据需要自行修改和扩展这些例子,以适应具体的项目需求。
转载请注明出处:http://www.zyzy.cn/article/detail/4030/CSS