前端(HTML,CSS)篇
1.安装软件(HBuilder X)
2.入门创建项目

3.基本HTML标签
- **`<html>`** - 定义了整个HTML文档。
- **`<head>`** - 包含文档的元数据,如字符集声明、样式表链接等。
- **`<title>`** - 设置浏览器标签页上显示的标题。
- **`<body>`** - 包含所有可见的内容,比如文本、图片等。
- **`<h1>` 到 `<h6>`** - 从最重要的到最不重要的六个级别的标题。
- **`<p>`** - 定义一个段落。
- **`<strong>` 或 `<b>`** - 渲染为粗体文本,用于强调。
- **`<em>` 或 `<i>`** - 渲染为斜体文本,用于强调。
- **`<br>`** - 插入一个换行符。
- **`<hr>`** - 创建水平线以分隔内容。
- **`<a>`** - 创建一个超链接到另一个页面或当前页面内的位置。
- **`<img>`** - 嵌入图像。
- **`<ul>`** - 创建无序列表(项目符号)。
- **`<ol>`** - 创建有序列表(编号)。
- **`<li>`** - 列表中的每一个项目。
- **`<table>`** - 定义表格。
- **`<tr>`** - 定义表格中的一行。
- **`<td>`** - 定义表格中的一个单元格。
- **`<th>`** - 定义表格中的表头单元格。
- **`<form>`** - 定义一个表单,用于收集用户输入。
- **`<input>`** - 定义一个输入字段,可以是多种类型如文本、密码、复选框等。
- **`<button>`** - 创建一个按钮。
- **`<select>` 和 `<option>`** - 创建下拉列表。
- **`<textarea>`** - 创建多行文本输入控件。
- **`<button>`** - 创建一个可点击的按钮。可以在`<button>`标签内添加文本或者HTML内容。
4.基本的CSS声明
- **选择器**:用于选择需要应用样式的HTML元素。
- **声明**:由一个属性和一个值组成,定义了如何显示被选中的元素。
- **规则集**:一组或多组声明,应用于通过选择器指定的一个或多个元素。
- **元素选择器**:直接使用HTML标签名作为选择器。
- **类选择器**:以`.`开始,后面跟着类名,应用于具有特定`class`属性的元素。
- **ID选择器**:以``开始,后面跟着ID名,应用于具有特定`id`属性的元素。
- **通用选择器**:使用`*`,应用于所有元素。
- **后代选择器**:两个选择器之间用空格隔开,表示选择某个元素内部的所有符合条件的后代元素。
- **子选择器**:两个选择器之间用`>`连接,表示选择某个元素的所有直接子元素。
- 属性: 值;
5.基本的CSS标签
文本样式
-
color
- 设置文本的颜色。
p {
color: #333; /* 十六进制颜色值 */
}
-
font-family
- 设置文本的字体系列。
h1 {
font-family: Arial, sans-serif;
}
-
font-size
- 设置文本的大小。
p {
font-size: 16px;
}
-
font-weight
- 设置文本的粗细。
strong {
font-weight: bold;
}
-
text-align
- 设置文本的对齐方式。
h1 {
text-align: center;
}
-
line-height
- 设置行高。
p {
line-height: 1.5;
}
-
text-decoration
- 添加或删除文本装饰。
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
背景样式
-
background-color
- 设置元素的背景颜色。
body {
background-color: #f0f0f0;
}
-
background-image
- 设置元素的背景图像。
.hero {
background-image: url('hero.jpg');
}
-
background-repeat
- 控制背景图像是否重复及如何重复。
.hero {
background-repeat: no-repeat;
}
-
background-position
- 设置背景图像的位置。
.hero {
background-position: center;
}
盒模型
-
width
和 height
- 设置元素的宽度和高度。
.box {
width: 200px;
height: 200px;
}
-
padding
- 设置内边距。
.box {
padding: 10px;
}
-
border
- 设置边框。
.box {
border: 1px solid #000;
}
-
margin
- 设置外边距。
.box {
margin: 10px;
}
显示与定位
-
display
- 控制元素的显示类型。
.block {
display: block;
}
.inline {
display: inline;
}
.none {
display: none;
}
-
position
- 控制元素的定位方式。
.relative {
position: relative;
top: 10px;
left: 10px;
}
.absolute {
position: absolute;
top: 10px;
right: 10px;
}
.fixed {
position: fixed;
bottom: 0;
right: 0;
}
-
z-index
- 控制元素的堆叠顺序。
.overlay {
z-index: 10;
}
其他常用属性
-
opacity
- 设置元素的透明度。
.fade {
opacity: 0.5;
}
-
transition
- 设置过渡效果。
.button {
transition: background-color 0.3s ease;
}
.button:hover {
background-color: #ff0000;
}
-
box-shadow
- 设置阴影效果。
.card {
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3);
}
-
border-radius
- 设置圆角边框。
.rounded {
border-radius: 5px;
}
6.示例代码
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>我的网站</title>
<link rel="stylesheet" href="/css/styles.css">
</head>
<body>
<h1>欢迎来到我的网站</h1>
<p>这是一个段落。</p>
<a href="#">链接</a>
<img src="./img/demo.png" alt="图片">
<ul>
<li>项目1</li>
<li>项目2</li>
</ul>
<table>
<tr>
<th>表头1</th>
<th>表头2</th>
</tr>
<tr>
<td>数据1</td>
<td>数据2</td>
</tr>
</table>
<form>
<input type="text" placeholder="输入文字...">
<button type="submit">提交</button>
</form>
</body>
</html>
/* 根元素 */
html {
font-family: Arial, sans-serif;
}
/* 文档标题 */
h1 {
color: #333;
text-align: center;
}
/* 段落 */
p {
line-height: 1.6;
color: #555;
}
/* 链接 */
a {
color: blue;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
/* 图像 */
img {
max-width: 100%;
height: auto;
display: block;
margin: 0 auto;
}
/* 列表 */
ul {
list-style-type: square;
}
/* 表格 */
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f4f4f4;
}
/* 表单 */
input[type="text"] {
width: 100%;
padding: 10px;
margin-bottom: 10px;
box-sizing: border-box;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}