一、HTML概述
一个网页就好像一幢房子,HTML结构就是钢筋混泥土的墙,一幢房子如果没有钢筋混泥土的墙那就是一堆废砖头,也就称不上是房子了。综上,HTML其实就是网页的结构+内容。
1、新建网页
代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<title>页面标题</title>
</head>
<body>
<h1>我的第一个Web页</h1>
<p>当前有点丑:)</p>
</body>
</html>
二、HTML简单应用
HTML元素:
1、html /html:根元素,其它元素都嵌套到其中。
2、 a /a:超链接元素
3、 h1 /h1:一级标题
4、th /th:表头(加粗)
5、td /td:表格等
6、br, hr, input,img:空元素
其中一个属性必须包含如下内容:
①一个空格,在属性和元素名称之间。(如果已经有一个或多个属性,就与前一个属性之间有一个空格)
②属性名称,后面跟着一个 = 号。
③一个属性值,由一对引号 “” 引起来。
1、增加注释
现在让我来加一个不显示的注释试试~
打开页面发现页面确实没有改变,成功!
2、增加空元素
代码如下:
<!-- 换行 -->
<p>我可以<br>换行</p>
<!-- 水平分割线 -->
<hr>
<!-- 输入框 -->
<input>
3、增加六级标题
代码如下:
<h1>This is heading 1</h1>
<p>This is some text.</p>
<hr>
<h2>This is heading 2</h2>
<p>This is some other text.</p>
<hr>
<h3>This is heading 3</h3>
<h4>This is heading 4</h4>
<h5>This is heading 5</h5>
<h6>This is heading 6</h6>
4、不同的文本格式
代码如下:
<p>You can use the mark tag to <mark>highlight</mark> text.</p>
<p><del>This line of text is meant to be treated as deleted text.</del></p>
<p><s>This line of text is meant to be treated as no longer accurate.</s></p>
<p><ins>This line of text is meant to be treated as an addition to the document.</ins></p>
<p><u>This line of text will render as underlined</u></p>
<p><small>This line of text is meant to be treated as fine print.</small></p>
<p><strong>This line rendered as bold text.</strong></p>
<p><em>This line rendered as italicized text.</em></p>
5、增加超链接
代码如下:
<p> 以下是一个超链接展示</p>
<a href="https://www.baidu.com/" target="_blank">百度一下</a>
6、插入图片
文件路径如下:
①img src=“picture.jpg”
该图片文件与当前文档在同一目录中
②img src="./images/picture.jpg"
该图片文件在当前目录下的images目录中
③img src="…/picture.jpg"
该图片文件在上一级目录中
我的代码如下:
<img src="tx1.jpeg" alt="MDB Logo" width="300" height="600">
7、表格和列表
代码如下:
<ul> <li>Coffee</li>
<li>Tea</li> <li>Milk</li>
</ul><ul type="square">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul><ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li></ol>
<ol type="a">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
8、制作简易表单
<form>
<!-- 文本框,注意有 placeholder 提示符 -->
用户名:<br>
<input type="text" name="name" placeholder="请输入用户名"><br>
<!-- 密码框 -->
密码:<br>
<input type="password" name="ps" placeholder="请输入密码"><br>
年龄:<br>
<!-- 数字输入框,注意 min 和 value 属性-->
<input type="number" name="age" min="18" value="18"><br>
<!-- 单选按钮, 注意 checked 属性 -->
性别:<br>
<input type="radio" name="gender" value="male" checked> 男<br>
<input type="radio" name="gender" value="female"> 女<br>
<input type="radio" name="gender" value="other"> 其它<br>
<!-- 下拉列表,注意 selected 属性 -->
党派:<br>
<select name="party">
<option value="D">民主党</option>
<option value="R" selected>共和党</option>
<option value="N">无党派</option>
</select><br>
<!-- 多选框 -->
您有哪些交通工具:<br>
<input type="checkbox" name="vehicle1" value="Bike"> 自行车<br>
<input type="checkbox" name="vehicle2" value="Motocycle" checked> 摩托车<br>
<input type="checkbox" name="vehicle3" value="Car"> 轿车<br>
<input type="checkbox" name="vehicle4" value="Jet"> 飞机<br>
<!-- 日期选择器 -->
您的工作日期:<br>
<input type="date"><br>
<!-- 文件选择器 -->
上传您的照片:<br>
<input type="file" name="photo"><br>
<!-- 文本输入区域,注意 rows 和 cols 属性 -->
您的建议:<br>
<textarea name="message" rows="5" cols="30">
The cat was playing in the garden.
</textarea><br><hr>
<!-- 表单提交/重置按钮,将表单中的数据取消或传输给服务器端进行处理 -->
<input type="submit" value="提 交">
<input type="reset" value="重 置">
</form>
小结
本次实验跟着指导步骤做没有遇到什么大问题,除了一开始因为文件命名问题没有在浏览器打开页面外,一切都很顺利,放入了自己喜欢的图片很开森,明天再继续做,bye~