整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:

网页设计HTML零基础入门

、Html概述

Html是Hyper Text Mark-up Language 的首字母简写,意思是超文本标记语言,超文本指的是超链接,标记指的是标签,是一种用来制作网页的语言,这种语言由一个个的标签组成,用这种语言制作的文件保存的是一个文本文件,文件的扩展名为html或者htm,一个html文件就是一个网页,html文件用编辑器打开显示的是文本,可以用文本的方式编辑它,如果用浏览器打开,浏览器会按照标签描述内容文件渲染成网页,显示的网页可以从一个网页链接跳转到另一个网页。

二、Html标签语法

Html中标签分为 :成对标签和自闭合标签【空标签】

1、成对标签

成对出现,有开始标签必须有结束标签,内容包裹在两个标签中,而且开始标签名和结束标签名一致,并且结束标签必须以斜杠/开头

语法:

<font>内容</font>

2、自闭合标签

只有一个标签,用斜杠结束,斜杠也可以省略

语法:

<br/>

注意事项:

  • 成对标签中,结束标签必须以斜杠开头
  • 成对标签与成对标签可以嵌套不能交叉
  • 标签名不区分大小写,但是我们都必须小写

三、Html基本架构

<!DOCTYPE html>
<html lang="en">
<head>
    <title></title>
</head>
<body>
    
</body>
</html>

1、!DOCTYPE

!DOCTYPE html是文档声明,定义文档类型为html,并且告诉不同的浏览器用标准方式进行解析html语言,如果不写的话,会产生怪异模式,所谓怪异模式,就是浏览器会用自己的方式进行解析,不同的浏览器有各自的解析方式,从而会出现无效果、不兼容等问题。

注意,html中有两种声明类型,一种叫做xhtml,即html,另一种叫做html5,html5是xhtml的升级版,所以我们建议使用html5的声明方式

xhtml声明方式:

<htmlxmlns="http://www.w3.org/1999/xhtml">

html5声明方式:

<!DOCTYPE html>

2、html

html是html文档的整体,也就是表示一个网页。

html中的lang="en"是定义该文件语言是英文

3、head

head是html的第一层子元素【子标签】,负责对网页进行一些设置以及定义标题,设置包括定义网页的编码格式,外链css样式文件和JavaScript文件等。设置的内容不会显示在网页上,标题的内容会显示在标题栏中。即title标签。

4、meta

meta是html语言head标签中的一个辅助性标签,该标签不包含任何内容,但是该标签的属性定义了与文档相关联的名称,比如:编码

<meta charset="utf-8"></meta>

5、body

body也是html的第一层子元素,我们页面中显示的所有内容全部都是编写在该标签体中。

四、Html文档规范

html制定了文档的编写规范,必须遵守。

所有的标签必须小写

所有的属性必须用双引号括起来

五、Html注释

html文档代码中可以插入注释,注释是对代码的说明和解释,注释的内容不会显示在页面上。

注释的语法:

<!-- 注释的内容 -->

六、html基本属性

注:属性是标签的辅助作用。

属性 描述 bgcolor 设置网页的背景颜色 background 设置网页的背景图片

1.bgcolor

设置网页的背景颜色

<!DOCTYPE html>
<html lang="en">
<head>
    <title>html的属性</title>
</head>
<body bacolor="pink">
    
</body>
</html>

2.路径

我们在开发网页时,需要经常的插入图片、视频、文件等一些操作,但是我们需要指定文件所在的位置,这个位置就是所谓的路径

路径分为:

  1. 相对路径 指目标相对于当前文件的路径,网页结构设计中多采用这种方式来表示目标的路径。相对路径有多种表示方法,其表示的意义不尽相同。表示方法如下: ./ :代表文件所在的目录(可以省略不写)../ :代表文件所在的父级目录../../ :代表文件所在的父级目录的父级目录/ :代表文件所在的根目录【/ : 可以理解为目标文件的绝对路径】
  2. 绝对路径 指目标文件的完整路径,从盘符开始。

3.background

设置网页的背景图片

<!DOCTYPE html>
<html lang="en">
<head>
    <title>html的属性</title>
</head>
<body background="../images/10.jpg">
    
</body>
</html>

注意事项:

bgcolor和background不能同时使用

background不能指定绝对路径

七、Html标签

1.网页的组成

网页的组成:文字、图片、视频、超链接、列表、表格、表单等组成。

2、文本段落标签

标签 描述 hn 设置文字标题【n:取值范围 1~6】 center 居中对齐 hr 水平线 属性(width:宽度 color:颜色 size:粗细) br 换行 p 段落

3、文本控制标签

标签 描述 font 设置字体,需要借助属性设置

属性 描述 color 设置字体颜色 size 设置字体大小,不需要带单位,取值范围:1~7【浏览器默认值:3】 face 设置字体风格

<font size="2" color="red" face="黑体"></font>

4、文本格式化标签

标签 描述 b 定义粗体文本 em 定义着重文字 i 定义斜体文字 small 定义小号字 strong 定义加重语气 sub 定义下标字 sup 定义上标字 ins 定义插入字 del 定义删除字

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Html文本格式化标签</title>
</head>
<body>

    <b>粗体文本</b>
    <i>倾斜文本</i>
    <em>着重文本</em>
    <small>小号字</small>
    <strong>加重语气</strong>
    <sub>上标</sub>
    <sup>下标</sup>
    <ins>插入字</ins>
    <del>删除字</del>
    
</body>
</html>

5、图片标签

在Html中,图像由

标签定义。

是空标签,意思是说,它只包含属性。

要在页面上显示图像,你需要使用源属性(src)。src指"source"。源属性的值是图像的URL地址。

标签 描述 img 图片标签

属性 描述 src 指定图片的地址 width 设置图片的宽度 height 设置图片的高度 alt 设置图片的预备文本

注意事项:不建议设置图片大小,容易失真

6、audio

在Html中,声音由标签定义。

标签 描述 audio 声音标签

属性 描述 src 指定声音地址

<audio src="nice.mp3">对不起,您的浏览器不支持</audio>

7、video

在Html中,视频由video标签定义

标签 描述 video 视频标签

属性 描述 src 指定视频地址

<video src="美女.mp4">对不起,您的浏览器不支持</video>

8、超链接

a标签定义超链接,用于从一个页面链接到另一个页面。

a标签最重要的属性是href,它指定链接的目标。

在所有浏览器中,链接的默认外观如下:

未被访问的链接带有下划线而且是蓝色的

已被访问的链接带有下划线而且是紫色的

活动链接带有下划线而且是红色的

语法:

<a href="链接目标">点击内容</a>

属性 描述 href 指定链接目标 name 指定锚的名称 download 指定下载链接 target 指定跳转方式 属性值 描述 _blank 新窗口打开【常用】 _parent 在父窗口中打开链接【了解】 _self 默认,在当前窗口打开【了解】 _top 在当前窗体打开链接,并替换当前的整个窗体【了解】 framename 到 iframe 在讲【常用】

超链接分类:

  • 内部链接 链接目标:本地页面 <a href="demo.html">点击内容</a>
  • 外部链接 链接目标:外部页面 <a href="http://www.baidu.com">点击内容</a>
  • 多媒体链接 链接目标:图片、视频等 <a href="images/美女.jpg">点击内容</a>
  • 电子邮件链接 链接目标:电子邮件【系统自带的电子邮件】 <a href="mailto:12345@qq.com">点击内容</a>
  • 锚链接 链接目标:锚点 1.建立锚点
    <
    a name="锚点名"></a>

    2.跳转
    <a href="#锚点名">点击内容</a>

9、列表

列表的使用与word等软件的列表概念相似,只不过是应用在网页展示中。

1.有序列表

有序列表是指有数字编号或字母的列表项,可以使用css定义更多样式。

<!-- 有序列表 -->
    <ol type="a">
        <li>新闻一</li>
        <li>新闻二</li>
        <li>新闻三</li>
    </ol>

属性 描述 type 设置符号类型 值:1 a A I i 默认数字 start 从第几个开始【用于ol标签中】 value 从第几个开始【用于li标签中】

<!-- 有序列表 -->
    <ol type="a" start="4">
        <li>新闻一</li>
        <li type="1" value="1">新闻二</li>
        <li>新闻三</li>
    </ol>

2、无序列表

无序列表是指没有数字编号或字母的列表项,可以使用css定义更多样式。

<!-- 无序列表 -->
<ul>
    <li>童装</li>
    <li>男装</li>
    <li>女装</li>
</ul>

属性 描述 type 用于设置符号类型,默认:实心圆 值:空心圆、正方形 【用于ul、li】

<!-- 无序列表 -->
<ul type="square">
        <li>童装</li>
        <li type="circle">男装</li>
        <li>女装</li>
    </ul>

3、描述列表

描述列表指每个列表项有单独的标题。

<!-- 描述列表 -->
    <dl>
        <dt>开源产品</dt>
        <dd>Java封装库</dd>
        <dd>Web组件库</dd>
        
        <dt>网站导航</dt>
        <dd>mrliujava.com</dd>
        <dd>mrliuweb.com</dd>
    </dl>

10、表格

表格在网页开发中使用频率非常高,尤其是数据展示的时候。

10.1 基本使用

标签 描述 table 代表表格标签 caption 表格标题 thead 表头部分 tbody 表格主体部分 tfoot 表格尾部

属性 描述 border 表格边框 cellspacing 单元格与单元格间距 width 宽度 height 高度 bgcolor 设置背景颜色 background 设置背景图片 align 对齐方式

<!-- 表格 -->
    <table border="1" cellspacing="0" width="600px" height="200px">
        <caption>员工薪资统计表</caption>
        <thead>
            <tr>
                <th>序号</th>
                <th>姓名</th>
                <th>性别</th>
                <th>职位</th>
                <th>薪资</th>
            </tr>
        </thead>

        <tbody>
            <tr>
                <td>1</td>
                <td>狗蛋</td>
                <td>男</td>
                <td>JavaEe工程师</td>
                <td>8780</td>
            </tr>

            <tr>
                <td>2</td>
                <td>黑妞</td>
                <td>女</td>
                <td>Web前端工程师</td>
                <td>9750</td>
            </tr>

            <tr>
                <td>3</td>
                <td>傻蛋</td>
                <td>妖</td>
                <td>测试工程师</td>
                <td>996</td>
            </tr>
        </tbody>

        <tfoot>
            <tr>
                <td>当前页:1 页</td>
                <td>上一页</td>
                <td>下一页</td>
                <td>尾页</td>
                <td>共 3 页</td>
            </tr>
        </tfoot>
    </table>

10.2 单元格合并

属性 说明 rowspan 行合并 colspan 列合并

下面是行合并:

<!-- 表格 -->
    <table border="1" cellspacing="0" width="600px" height="200px">
        <caption>员工薪资统计表</caption>
        <thead>
            <tr>
                <th>序号</th>
                <th>姓名</th>
                <th>性别</th>
                <th>职位</th>
                <th>薪资</th>
            </tr>
        </thead>

        <tbody>
            <tr>
                <td>1</td>
                <td>狗蛋</td>
                <td>男</td>
                <td rowspan="2">JavaEe工程师</td>
                <td>8780</td>
            </tr>

            <tr>
                <td>2</td>
                <td>黑妞</td>
                <td>女</td>
                <td>9750</td>
            </tr>

            <tr>
                <td>3</td>
                <td>傻蛋</td>
                <td>妖</td>
                <td>测试工程师</td>
                <td>996</td>
            </tr>
        </tbody>

        <tfoot>
            <tr>
                <td>当前页:1 页</td>
                <td>上一页</td>
                <td>下一页</td>
                <td>尾页</td>
                <td>共 3 页</td>
            </tr>
        </tfoot>
    </table>

下面是列合并:

<!-- 表格 -->
    <table border="1" cellspacing="0" width="600px" height="200px">
        <caption>员工薪资统计表</caption>
        <thead>
            <tr>
                <th>序号</th>
                <th>姓名</th>
                <th>性别</th>
                <th>职位</th>
                <th>薪资</th>
            </tr>
        </thead>

        <tbody>
            <tr>
                <td>1</td>
                <td>狗蛋</td>
                <td>男</td>
                <td>JavaEe工程师</td>
                <td>8780</td>
            </tr>

            <tr>
                <td>2</td>
                <td>黑妞</td>
                <td>女</td>
                <td>Web前端工程师</td>
                <td>9750</td>
            </tr>

            <tr>
                <td>3</td>
                <td colspan="2">傻蛋</td>
                <td>测试工程师</td>
                <td>996</td>
            </tr>
        </tbody>

        <tfoot>
            <tr>
                <td>当前页:1 页</td>
                <td>上一页</td>
                <td>下一页</td>
                <td>尾页</td>
                <td>共 3 页</td>
            </tr>
        </tfoot>
    </table>

11、表单

表单是一个包含表单元素的区域。

表单元素是允许用户在表单中输入内容,比如:文本域(textarea)、下拉列表(select)、单选框(radio)、复选框(checkbox)等等。

11.1 基本使用

表单需要使用表单标签来设置:

<!-- 表单 -->
<form>
input元素
</form>

11.2 GET&POST

属性 说明 action 后台地址 method 提交方式GET或POST

GET和POST区别:

1.GET

  • 数据会显示在地址栏中,数据不安全
  • 数据大小有限制
  • 数据通过请求头传递

2.POST

  • 数据不会显示在地址栏中,数据安全
  • 数据对大小无限制
  • 数据通过实体内容传递
<form action="后端接口" method="POST">
        <input type="text">
        <input type="password">
</form>

11.3 LABEL

使用label用于描述表单标题,当点击标题后文本框会获得焦点,需要保证使用的ID在页面中是唯一的。

<form action="后端接口" method="POST">
        <label for="username">用户名</label>
        <input type="text" id="username">

        <label for="password">密码</label>
        <input type="password" id="password">
</form>

也可以将文本框放在label标签内部,这样就不需要设置id与for属性了。

11.4 INPUT

文本框用于输入单行文本使用,下面是常用属性与示例。

属性 说明 type 表单类型,默认为text name 后端接收字段名 required 必须输入 placeholder 提示文本内容 value 默认指 maxlength 允许最大输入字符数 size 表单长度,一般用css来控制 disabled 禁用,不可提交后端 readonly 只读,可提交后端 accept 设置选中类型 比如:.jpg capture 使用麦克风\视频或摄像头哪种方式获取手机上传文件,支持的值有microphone , video , camera

11.4.1 基本示例

<form action="后端接口" method="POST">
        <label for="username">用户名</label>
        <input type="text" name="username" id="username" placeholder="请输入用户名" maxlength="5" size="50" required>
</form>

11.4.2 调用摄像头

当input类型为file时手机会让用户选择图片或者拍照,如果想直接调取摄像头使用以下代码.

<form action="后端接口" method="POST">
        <label for="file">上传文件</label>
        <input type="file" name="file" id="file" accept="*.jpg" capture="camera">
</form>

11.4.3 其他类型

通过设置表单的type字段可以指定不同的输入内容.

类型 说明 email 输入内容为邮箱 url 输入内容为URL地址 password 输入内容为密码项 tel 电话号,移动端会调出数字键盘 search 搜索框 hidden 隐藏表单 submit 提交表单 reset 重置表单 button 自定义按钮

11.4.4 HIDDEN

隐藏表单用于提交后台数据,但在前台内容不显示所以在其上做用样式定义也没有意义.

<input type="hidden" name="id" value="1">

11.4.5 SUBMIT

创建提交按钮可以将表单数据提交到后台,有多种方式可以提交数据,比如:AJAX,或者Html的表单按钮.

a.使用input构建提交按钮,如果设置了name值,那么按钮数据也会提交到后台,如果有多个表单项可以通过这些进行判断是哪个表单提交的.

<input type="submit" name="submit" value="提交表单">

b.使用button也可以提交,设置type属性为submit或不设置都可以提交表单.

<button type="submit">提交表单</button>

11.4.6 禁用表单

通过为表单设置disabled或readonly都可以禁止表单,单readonly表单的数据可以提交到后端

<input type="text" value="数据" readonly>

11.4.7 PATTERN

表单可以通过设置pattern属性指定正则验证.

属性 说明 pattern 正则表达式验证规则 oninvalid 输入错误时触发的事件

<form action="">
        <label for="username">用户名</label>
        <input type="text" name="username" id="username" pattern="[a-z]{5,20}" oninvalid="validate('请输入5~20位字母的用户名')">
        <button>提交表单</button>
    </form>

    <script>
        function validate(message){
            alert(message);
        }
    </script>

11.4.8 TEXTAREA

文本域指可以输入多行文本的表单,当然更复杂的情况可以使用编辑器如ueditor , ckeditor等.

属性 说明 cols 列字符数(一般使用css控制更好) rows 行数(一般使用css控制更好)

<textarea cols="30" rows="3">请踩踩我......</textarea>

11.4.9 SELECT

下拉列表项可用于多个值中的选择.

属性 说明 multiple 支持多选 size 列表框高度 optgroup 选项组 selected 选中状态 option 选项值

<form action="">
        <select multiple size="10">
            <option value="">选择课程</option>
            <optgroup label="后端">
                <option value="">JAVA</option>
                <option value="">PHP</option>
                <option value="">LINUX</option>
            </optgroup>

            <optgroup label="前端">
                <option value="">HTML</option>
                <option value="">CSS</option>
                <option value="">JAVASCRIPT</option>
            </optgroup>
        </select>
    </form>

11.4.10 RADIO

单选框指只能选择一个选项的表单,如性别的选择:男 , 女 , 保密 只能选择一个.

属性 说明 checked 选中状态

<form action="">
        <input type="radio" name="" id="boy" checked>
        <label for="boy">男</label>

        <input type="radio" name="" id="girl">
        <label for="girl">女</label>
    </form>

11.4.11 CHECKBOX

复选框指允许选择多个值的表单

属性 说明 checked 选中状态

<form action="">
        <input type="checkbox" name="JAVA" id="java">
        <label for="java">JAVA</label>

        <input type="checkbox" name="WEB" id="web">
        <label for="web">WEB</label>
    </form>

11.4.12 FILE

文件上传有很多方式,可以使用插件或者JS拖放上传处理.Html本身也提供了默认的上传功能,只是上传效果并不是很美观.

属性 说明 multiple 支持多选 accept 允许上传类型.png , .psd 或者 image/png , image/gif

<form action="" enctype="multipart/form-data">
        <input type="file">
        <input type="submit" value="上传">
    </form>

11.4.13 日期时间

属性 说明 min 最小时间 max 最大时间 step 间隔: date缺省是1天 week缺省是1周 month缺省是1月

a.日期选择

<h1>日期选择</h1>
    <form action="">
        <input type="date" step="5" min="2020-09-22" max="2025-01-15" name="datetime">
    </form>

b.周选择

<h1>周选择</h1>
    <input type="week" name="" id="">

c.月份选择

<h1>月选择</h1>
    <input type="month" name="" id="">

d.日期与时间

<h1>日期与时间</h1>
    <input type="datetime-local" name="" id="">

11.4.14 DATALIST

input表单的输入值选项列表

<form action="">
        <label for="username">用户名</label>
        <input type="text" name="" id="usernmae" list="less">
        <datalist id="less">
            <option value="JAVA">后台管理语言</option>
            <option value="CSS">美化网站页面</option>
            <option value="MYSQL">掌握数据库使用</option>
        </datalist>
    </form>

12、框架集

frameset元素可定义一个框架集。它被用来组织多个窗口(框架),每个框架存有独立的文档,在其最简单的应用中,frameset元素仅仅会规定在框架集中存在多少列或多少行,您必须使用cols或rows属性。

注意事项:由于是分割原网页,所以我们不能在body中进行编写,在head中进行分割。

标签 说明 frameset 框架集 frame 框架

属性 说明 cols 定义框架集中列的数目和尺寸 rows 定义框架集中行的数目和尺寸 frame border 去除框架边框 scrolling 去除滚动条

12.1 垂直框架

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Html垂直框架</title>

    <frameset cols="50%,*" >
        <frame src="http://www.baidu.com" frameborder="0" scrolling="no"></frame>
        <frame src="http://www.taobao.com" frameborder="0"  scrolling="no"></frame>
    </frameset>
</head>
<body>
    
</body>
</html>

12.2 水平框架

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>Html水平框架</title>
		<frameset rows="50%,*" >
				<frame src="http://www.baidu.com" frameborder="0" scrolling="no"></frame>
        <frame src="http://www.taobao.com" frameborder="0" scrolling="no"></frame>
		</frameset>
	</head>
<body>
</body>
</html>

12.3 混合框架

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Html混合框架</title>

    <frameset rows="20%,*" >
        <frame src="http://www.baidu.com" frameborder="0" scrolling="no"></frame>
        <frameset cols="20%,*">
            <frame src="http://www.taobao.com" frameborder="0" scrolling="no"></frame>
            <frame src="https://www.huya.com/" frameborder="0" scrolling="no"></frame>
        </frameset>
        
    </frameset>
</head>
<body>
    
</body>
</html>

12.4 导航框架

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Html美女</title>
</head>
<body>
    
    <img src="../images/10.jpg" alt="">

</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Html野兽</title>
</head>
<body>
    

    <img src="../images/timg.gif" alt="">

</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Html动物</title>
</head>
<body>
    
    <img src="../images/4.jpg" alt="">

</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Html链接</title>
</head>
<body>

    <a href="Html美女.html" target="view">美女图片</a>
    <a href="Html野兽.html" target="view">野兽图片</a>
    <a href="Html动物.html" target="view">动物图片</a>
    
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Html垂直框架</title>

    <frameset rows="20%,*" >
        <frame src="http://www.baidu.com" frameborder="0" scrolling="no"></frame>
        <frameset cols="20%,*">
            <frame src="Html链接.html" frameborder="0" scrolling="no"></frame>
            <frame src="https://www.huya.com/" frameborder="0" scrolling="no" name="view"></frame>
        </frameset>
        
    </frameset>
</head>
<body>
    
</body>
</html>

13、内联框架

iframe元素会创建包含另外一个文档的内联框架。

属性 说明 align 对齐方式,后期采用css的方式进行设置 width 设置宽度 height 设置高度 src 设置iframe中显示的文档的URL name iframe的名称 scrolling 是否显示滚动条 frameborder 设置iframe的边框

么是Canvas

<canvas> 是HTML中的一个元素,它可被用来通过 JavaScript(Canvas API 或 WebGL API)绘制图形及图形动画。

Canvas API 提供了一个通过 JavaScriptHTML<canvas> 元素来绘制图形的方式。它可以用于动画、游戏画面、数据可视化、图片编辑以及实时视频处理等方面。

<canvas>标签本身没有绘图能力,它仅仅是图形的容器。在HTML,一般通过Javascript语言来完成实际的操作。

创建HTML页面并添加绘图容器

本文通过Javascript操作Canvas制作一个简单的显示当前时间的动画时钟,了解和学习简单的canvas用法,仅以抛砖引玉。

首先创建一个HTML文件,为了方便管理,使用一个div标签包裹两个canvas标签,并加上一些简单的css样式。

<!doctype html>
<html lang="zh-cn">
<head><title>Canvas绘制动画时钟</title>
<style>
html,body{margin:0;padding:0}
#clockWrap {
	position: relative;
}
canvas {
	position: absolute;
}
#clock-ui {
	z-index: 2;
}
#clock-plate {
	z-index: 1;
}
</style>
</head>
<body>
  <div id="clockWrap">
  <canvas id="clock-plate"></canvas>
  <canvas id="clock-ui"></canvas>
</div>
<script></script>
</body></html>

本示例中使用了两个canvas标签(为什么使用两个,一个不是更简单吗?),一个用于绘制钟面,一个根据当前时间实时显示和更新时针、分针和秒针的动态指向。好了,话不多说,开干。

绘制钟面刻度

一个简单的时钟,可以分为钟面上的刻度和指针。其中刻度和12个数字是固定的,我们可以将它们绘制在当作背景的canvas上(示例中id为clock-plate的canvas)。

(1)要使用canvas,首先必须通过容器获取渲染上下文:

var $=function(id){return document.querySelector(id);}//这个函数只是为了方便获取dom元素
const canvasbg=$("#clock-plate"),
      canvas=$("#clock-ui"),
      ctx = canvasbg.getContext("2d"),//背景容器上下文
      ctxUI = canvas.getContext("2d");//指针容器上下文,后面代码要用
//定义画布宽度和高度,时钟圆直径,并设置画布大小
const oW=1000,oH=800,cW=400,r=cW/2,oX=oW/2,oY=oH/2;
canvas.width=oW;
canvas.height=oH;
canvasbg.width=oW;
canvasbg.height=oH;

(2)画钟的边框,为了好看,这里画两个圈:

 //画出时钟外圆框
  ctx.lineWidth = 12;
	ctx.beginPath();
	ctx.arc(oX, oY, r+14, 0, 2 * Math.PI);
	ctx.stroke();
	ctx.closePath();
	ctx.lineWidth = 8;
	//画出时钟内圆框(刻度圈)
	ctx.beginPath();
	ctx.arc(oX, oY, r, 0, 2 * Math.PI);
	ctx.stroke();
	ctx.closePath();
	ctx.beginPath();

边框效果图

(3)绘制刻度线和数字,可以利用三角函数计算出每个刻度的坐标:

利用三角函数计算刻度线的坐标位置

钟面上有12个大格,从正上方12开始,它们的度数分别是270,300,330,0,30,60,90,120,150,180,210,240。然后利用JS的Math.sin和Math.cos分别计算出各大格的坐标。注意:js中Math.sin()和Math.cos()的参数不是角度数弧度。可以使用Math.PI/180*角度来转化,比如将30度转换成弧度=Math.PI/180*30

//绘制钟表中心点
	ctx.beginPath();
	ctx.arc(oX, oY, 8, 0, 2 * Math.PI);//圆心
	ctx.fill();
	ctx.closePath();
	//设置刻度线粗细度
	ctx.lineWidth = 3;
	//设置钟面12个数字的字体、大小和对齐方式
	ctx.font = "30px serif";
	ctx.textAlign="center";
	ctx.textBaseline="middle";
	var kdx,kdy;
	//绘制12个大刻度和12个数字
	//为方便计算,先定义了0-11这12个刻度对应的度数,也可以直接定义对应的弧度。
	const hd=Math.PI/180,degr=[270,300,330,0,30,60,90,120,150,180,210,240];
	for(var i=0;i<12;i++){
		kdx=oX+Math.cos(hd*degr[i])*(r-3);
		kdy=oY+Math.sin(hd*degr[i])*(r-3);
		ctx.beginPath();
		ctx.arc(kdx, kdy, 6, 0, 2 * Math.PI);//画圆形大刻度
		ctx.fill();
    //绘制刻度对应的数字
		ctx.strokeText(i==0? 12 : i,oX+Math.cos(hd*degr[i])*(r-24),oY+Math.sin(hd*degr[i])*(r-24));
		ctx.closePath();
	}
	
	//绘制小刻度
	ctx.lineWidth = 2;
	for(var i=0;i<60;i++){
		if(i % 5 == 0) continue;//跳过与刻度重叠的刻度
		x0=Math.cos(hd*i*6);
		y0=Math.sin(hd*i*6);
		ctx.beginPath();
		ctx.moveTo(oX+x0*(r-10), oY+y0*(r-10)); 
		ctx.lineTo(oX+x0*r, oY+y0*r); //画短刻度线
		ctx.stroke(); 
		ctx.closePath();
	}

效果如图:

钟面效果图

(4)根据当前时间绘制指针

习惯上,时针粗短,分针略粗而长,秒针细长。为加大区别,示例中秒针细长并且绘制成红色。

function drawHp(i){//绘制时针
	const x0=Math.cos(hd*i*30),y0=Math.sin(hd*i*30);
	drawPointer(oX,oY,oX+x0*(r-90),oY+y0*(r-90),10,"#000000");
}
function drawMp(i){//绘制分针
	const x0=Math.cos(hd*i*6),y0=Math.sin(hd*i*6);
	drawPointer(oX,oY,oX+x0*(r-60),oY+y0*(r-60),5,"#000000");
}
function drawSp(i){//绘制秒针
	const x0=Math.cos(hd*i*6),y0=Math.sin(hd*i*6);
	drawPointer(oX,oY,oX+x0*(r-20),oY+y0*(r-20),2,"#FF0000");
}
//抽取出绘制三种指针时共同的部分,注意指针绘制在渲染上下文ctxUI中
function drawPointer(ox,oy,tx,ty,width,color){
	ctxUI.strokeStyle = color;
	ctxUI.lineCap = "round";
	ctxUI.lineWidth = width;
	ctxUI.beginPath();
	ctxUI.moveTo(ox, oy);
	ctxUI.lineTo(tx,ty);
	ctxUI.stroke();
	ctxUI.closePath();
}

现在已经有了绘制三种指针的方法,参数是当前时间的时、分和秒,将根据它们的值确定指针的坐标。不过,因为使用的是默认的convas坐标体系,0值实际指向3的位置,需要小小的修正一下。

window.requestAnimationFrame(function fn(){
		var d = new Date();
		ctxUI.clearRect(0,0,oW,oH);
		//度数从0开始,而0在3刻度(15分/秒位置),修正为全值减15,如果小于0则修正回来
    var hour=d.getHours(),minute=d.getMinutes()-15,second=d.getSeconds()-15;
		hour=hour>11? hour-15 : hour-3;
		drawHp(hour>=0? hour : 12+hour);
		drawMp(minute>=0? minute : 60+minute);
		drawSp(second>=0? second : 60+second);
		window.requestAnimationFrame(fn);
});

接下来,调用window.requestAnimationFrame,在其中绘制并更新指标的位置。看看效果如何:

指针绘制情况与实际时间相符

貌似效果有了,截图时电脑上的时间是10时17分,指针绘制上,时针指向10时,分针指向17。嗯,感觉有点别扭?对了,时针和分针怎么是端端正正地指向它们的整时整分刻度上呢?实际钟表上时针和分针是展示动态进度的,此时时针应该越过10时的位置才对。没关系,我们在绘制时针和分针时别点东西,让它的角度值加上分针和秒针的值试试。

//修改后的绘制三种指针的方法
function drawHp(i,f,m){//绘制时针,参数:时,分,秒
	const x0=Math.cos(hd*(i+(f/60)+(m/600))*30),y0=Math.sin(hd*(i+(f/60)+(m/600))*30);
	drawPointer(oX,oY,oX+x0*(r-90),oY+y0*(r-90),10,"#000000");
}
function drawMp(i,f){//绘制分针,参数,分,秒
	const x0=Math.cos(hd*(i+(f/60))*6),y0=Math.sin(hd*(i+(f/60))*6);
	drawPointer(oX,oY,oX+x0*(r-60),oY+y0*(r-60),5,"#000000");
}
function drawSp(i){//绘制秒针
	const x0=Math.cos(hd*i*6),y0=Math.sin(hd*i*6);
	drawPointer(oX,oY,oX+x0*(r-20),oY+y0*(r-20),2,"#FF0000");
}

再来看看效果,嗯,立竿见影呀:

指针指向更合理了

到此为止,canvas绘制一个简易时钟就完成了。下面继续优化一下。刚才使用requestAnimationFrame方法即时更新绘制情况。这个方法与刷新率有关,看看mdn上面怎么说的:

window.requestAnimationFrame() 方法会告诉浏览器你希望执行一个动画。它要求浏览器在下一次重绘之前,调用用户提供的回调函数。

对回调函数的调用频率通常与显示器的刷新率相匹配。虽然 75hz、120hz 和 144hz 也被广泛使用,但是最常见的刷新率还是 60hz(每秒 60 个周期/帧)。为了提高性能和电池寿命,大多数浏览器都会暂停在后台选项卡或者隐藏的 <iframe> 中运行的 requestAnimationFrame()。

本示例中,更新指针的位置并不需要很高的刷新频率,可以通过节流进行一下优化:

var fps = 5, fpsInterval = 1000 / fps,lastTime = new Date().getTime(); //记录上次执行的时间
function runStep() {
    requestAnimationFrame(runStep);
    var d=new Date(),now = d.getTime()
    var elapsed = now - lastTime;
    if (elapsed > fpsInterval) {
				ctxUI.clearRect(0,0,oW,oH);
        lastTime = now - (elapsed % fpsInterval); 
			//度数从0开始,而0在3刻度(15分/秒位置),修正为全值-15,如果小于0则用60减回
        var hour=d.getHours(),minute=d.getMinutes()-15,second=d.getSeconds()-15;//console.log(d.getSeconds(),second);
        hour=hour>11? hour-15 : hour-3;
        drawHp(hour>=0? hour : 12+hour,minute+15,second+15);
        drawMp(minute>=0? minute : 60+minute,second+15);
        drawSp(second>=0? second : 60+second);
    }
}
runStep();

当然,实现时钟的方法是很多,比如可以使用画布的旋转(rotate方法)来实现指针的动态转动等等。

完整HTML+JS源码:

雪时间轴个人博客模板,女生唯美简洁个人博客静态页面模板,蓝色时间轴个人网页模板,下雪空间个人模板代码

1、html页面代码

<!doctype html>
<html>
<head>
<meta charset="gb2312">
<title>看雪时间轴个人博客模板 - bokequ.com</title>
<meta name="keywords" content="蓝色模板,个人网站模板,个人博客模板,博客模板,css3,html5,网站模板" />
<meta name="description" content="这是一个有关看雪时间轴的css3 html5 网站模板" />
<link href="css/styles.css" rel="stylesheet">
<link href="css/animation.css" rel="stylesheet">
<!-- 返回顶部调用 begin -->
<link href="css/lrtk.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/js.js"></script>
<!-- 返回顶部调用 end-->
<!--[if lt IE 9]>
<script src="js/modernizr.js"></script>
<![endif]-->
</head>
<body>
<header> <img src="http://www.bokequ.com/winter/templets/xq/images/logo.png" alt="看雪个人空间" width="170" height="60">
  <h1><a href="http://www.bokequ.com/winter/">看雪时间轴个人博客模板</a></h1>
  <p>看雪,是一种唯美的心境。这个冬季,放下疲惫的自己,一起看雪吧</p>
</header>
<div class="b_nav"></div>
<div id="nav">
  <ul>
   <li><a href="#">网站首页</a></li>
    <li><a href="http://www.bokequ.com/blog/1/" target="_blank" title="个人博客模板">个人博客模板</a></li>
    <li><a href="#"  title="图书推荐">图书推荐</a></li>
    <li><a href="#" title="网站建设">网站建设</a></li>
    <li><a href="http://www.bokequ.com/category/web" target="_blank" title="HTML5 / CSS3">HTML5/CSS3</a></li>
    <li><a href="#" target="_blank" title="技术探讨">技术探讨</a></li>
    <li><a href="http://www.bokequ.com/wo/life/man/" target="_blank" title="慢生活">慢生活</a></li>
    <li><a href="http://www.bokequ.com/wo/newstalk/" target="_blank" title="碎言碎语">碎言碎语</a></li>
  </ul>
  <!--获取当前页导航 高亮显示标题-->
</div>
<!--header end-->
<div id="mainbody">
  <div class="info">
    <figure> <img src="images/art1.jpg"  alt="看雪,是一种唯美的心境">
      <figcaption><strong>看雪,是一种唯美的心境</strong>   喜欢雪,没有理由,只是爱它的轻盈,却不张扬;痴迷于它的典雅,却不做作。纯纯的颜色,洁白如晶,如天使,似鹅毛,飘飘洒洒,漫天飞舞。它虽没有华丽的外套,白色却是最好的衣冠;它虽称不上雍容华贵,素雅却是最佳的装扮。带着它的雅致,迈着绝美的舞姿,随着冬的到来而翩翩起舞,洋洋洒洒,一泻千里。 </figcaption>
    </figure>
    <div class="card">
      <h1>关于我</h1>
      <p>网名:keyboard | 草戊水来</p>
      <p>职业:Web前端设计师、网页设计</p>
      <p>电话:18666888333</p>
      <p>Email:snow@qq.com</p>
      <ul class="linkmore">
        <li><a href="#" class="talk" title="给我留言"></a></li>
        <li><a href="#" class="address" title="联系地址"></a></li>
        <li><a href="#" class="email" title="给我写信"></a></li>
        <li><a href="#" class="photos" title="生活照片"></a></li>
        <li><a href="#" class="heart" title="关注我"></a></li>
      </ul>
    </div>
  </div>
  <!--info end-->
  <div class="blank"></div>
  <div class="blogs">
    <ul class="bloglist">
      <li>
        <div class="arrow_box">
          <div class="ti"></div>
          <!--三角形-->
          <div class="ci"></div>
          <!--圆形-->
          <h2 class="title"><a href="http://www.bokequ.com/blog/12/1.html" target="_blank">雪,温暖了整个冬天。</a></h2>
          <ul class="textinfo">
            <a target="_blank" href="http://www.bokequ.com/blog/12/1.html"><img src="images/11.jpg"></a>
            <p>   冬天总是不如夏春秋一般柔软多情,既然来了,就让人记得刻苦铭心。人生如此般,雪一般的岁月,苦中作乐,暂不说这是那些文人雅客笔下描写的那样如诗如画,却也是每一个人的雪景中总有一处属于自己建立起的一片天地。如痴如醉的自己,看不清别人,也看不清自己,倒也是一种境界,让人有点糊涂,有点执迷。 </p>
          </ul>
          <ul class="details">
            <li class="likes"><a href="#">喜欢 10</a></li>
            <li class="comments"><a href="#">评论 34</a></li>
            <li class="icon-time"><a href="#">时间 2016-12-1</a></li>
          </ul>
        </div>
        <!--arrow_box end-->
      </li>
      <li>
        <div class="arrow_box">
          <div class="ti"></div>
          <!--三角形-->
          <div class="ci"></div>
          <!--圆形-->
          <h2 class="title"><a href="http://www.bokequ.com/wo/" target="_blank">说好陪我看第一场雪。雪下了,你在哪?</a></h2>
          <ul class="textinfo">
            <a href="#"><img src="images/s5.jpg"></a>
            <p>   1、雪很美, 当它落下来的那一刻,就注定要化成水。2、世界上没有不融化的雪,也没有永远不变的爱情,人心都是会变的。3、纯洁的雪,洗濯了肮脏的世界,邂逅的只是安静的大地。4、冬天下雪的时候他会背我走 可是我们分手了。5、冬天的早晨, 晴朗的阳光, 洁净安宁的雪, 一切美的就像我喜欢的她。6、当赤道留住雪花。眼泪融掉细沙,你肯珍惜我吗?</p>
          </ul>
          <ul class="details">
            <li class="likes"><a href="#">喜欢 102</a></li>
            <li class="comments"><a href="#">评论 58</a></li>
            <li class="icon-time"><a href="#">时间 2016-12-2</a></li>
          </ul>
        </div>
        <!--arrow_box end-->
      </li>
      <li>
        <div class="arrow_box">
          <div class="ti"></div>
          <!--三角形-->
          <div class="ci"></div>
          <!--圆形-->
          <h2 class="title"><a href="http://www.bokequ.com/wo/" target="_blank">风劲吹,雪漫舞</a></h2>
          <ul class="textinfo">
            <a href="#"><img src="images/s3.jpg"></a>
            <p>   雪花漫天卷地落下来,犹如鹅毛一般,纷纷扬扬。轻轻地轻轻地落在房顶上,落在草地上,落在山峰上。一会儿,大地一片雪白,好象整个世界都是银白色的,闪闪发光。雪落在地上,那么纯洁,那么晶莹,真使人不忍心踩上去...</p>
          </ul>
          <ul class="details">
            <li class="likes"><a href="#">喜欢 15</a></li>
            <li class="comments"><a href="#">评论 2</a></li>
            <li class="icon-time"><a href="#">时间 2016-12-3</a></li>
          </ul>
        </div>
        <!--arrow_box end-->
      </li>
      <li>
        <div class="arrow_box">
          <div class="ti"></div>
          <!--三角形-->
          <div class="ci"></div>
          <!--圆形-->
          <h2 class="title"><a href="http://www.bokequ.com/wo/" target="_blank">北京下雪了</a></h2>
          <ul class="textinfo">
            <a href="#"><img src="images/s4.jpg"></a>
            <p>   雪中的北京,好美,下雪天,是不是应该得到一个大大的拥抱,一杯喜欢的咖啡,牵手去踩踩雪,听着咯吱咯吱的声音。每年下雪的时候,都是我最想家的时候,以前北京下雪总是没有大连下的那么痛快,所以最冷的时候最怀念家乡的大学和温暖的被窝,原来寒冷真的会加重思乡之情……小伙伴们,你们还好吗?!</p>
          </ul>
          <ul class="details">
            <li class="likes"><a href="#">喜欢 102</a></li>
            <li class="comments"><a href="#">评论 58</a></li>
            <li class="icon-time"><a href="#">时间 2016-12-4</a></li>
          </ul>
        </div>
        <!--arrow_box end-->
      </li>
      <li>
        <div class="arrow_box">
          <div class="ti"></div>
          <!--三角形-->
          <div class="ci"></div>
          <!--圆形-->
          <h2 class="title"><a href="http://www.bokequ.com/wo/" target="_blank">看雪赏雪心情说说</a></h2>
          <ul class="textinfo">
            <a href="#"><img src="images/s1.jpg"></a>
            <p>   踏上由雪铺砌的小路,独自漫步,踩上去听那咯吱咯吱的乐声,真比那天籁之音还要醉人,难怪有诗这样写到“此曲只应天上有,人间哪得几回闻。”你瞧,远出那被雪覆盖的枯枝,似开出了一朵朵白色的小花,真有点“忽如一夜春风来,千树万树梨花开”的味道,却又好似玉雕的一般,晶莹剔透。还有那房屋上,也都披上了厚厚的雪戎装。</p>
          </ul>
          <ul class="details">
            <li class="likes"><a href="#">喜欢 15</a></li>
            <li class="comments"><a href="#">评论 2</a></li>
            <li class="icon-time"><a href="#">时间 2016-12-5</a></li>
          </ul>
        </div>
        <!--arrow_box end-->
      </li>
      <li>
        <div class="arrow_box">
          <div class="ti"></div>
          <!--三角形-->
          <div class="ci"></div>
          <!--圆形-->
          <h2 class="title"><a href="http://www.bokequ.com/wo/" target="_blank">因为爱你,更是因为懂你</a></h2>
          <ul class="textinfo">
            <a href="#"><img src="images/12.jpg"></a>
            <p>   外边仍然飘着转身急逝的雪花,多想在看看落满操场的雪花,多想和你踏着,听着雪碎的声音,如今只剩下惨淡的雪还在下,只能听见自己心碎的声音还在颤抖。望着你离开的背影,我告诉自己要坚强,不哭,是因为爱你,更是因为懂你。 </p>
          </ul>
          <ul class="details">
            <li class="likes"><a href="#">喜欢 15</a></li>
            <li class="comments"><a href="#">评论 2</a></li>
            <li class="icon-time"><a href="#">时间 2016-12-6</a></li>
          </ul>
        </div>
        <!--arrow_box end-->
      </li>
      <li>
        <div class="arrow_box">
          <div class="ti"></div>
          <!--三角形-->
          <div class="ci"></div>
          <!--圆形-->
          <h2 class="title"><a href="http://www.bokequ.com/wo/" target="_blank">长大后看雪,看的是心境</a></h2>
          <ul class="textinfo">
            <a href="#"><img src="images/art2.jpg"></a>
            <p>   许多人看雪会看出许多往事,像小时候看雪,看的就是纯净,长大后看雪,看的是心境。不同的人生阶段看到的雪花固然不同,有看出惊艳的,有看出伤感的,有看出华丽的,有看出苍白的,不论看到了什么样的心境,雪还是雪,只是落在谁的心上,就堆积成什么样的形状。我到真心认为,雪就是雪,季节的使者,有它的时经典散文摘抄:候,证明这个季节是狂欢的,没它的时候,这个季节会显得格外冷清。</p>
          </ul>
          <ul class="details">
            <li class="likes"><a href="#">喜欢 15</a></li>
            <li class="comments"><a href="#">评论 2</a></li>
            <li class="icon-time"><a href="#">时间 2016-12-7</a></li>
          </ul>
        </div>
        <!--arrow_box end-->
      </li>
      <li>
        <div class="arrow_box">
          <div class="ti"></div>
          <!--三角形-->
          <div class="ci"></div>
          <!--圆形-->
          <h2 class="title"><a href="http://www.bokequ.com/wo/" target="_blank">雪景清纯美女图片下载</a></h2>
          <ul class="textinfo">
            <a href="#"><img src="images/13.jpg"></a>
            <p>  雪,带着那冬季的清寒悄然飘落,雪花是多么美好,它纯净了整个世界,纯净了我们的心灵中的每一个角落。一起徒步看雪景也许最美的不是天长地久,而是和你一起坐在长椅上,看远处的雪景,天空很冷,我们却很幸福!</p>
          </ul>
          <ul class="details">
            <li class="likes"><a href="#">喜欢 15</a></li>
            <li class="comments"><a href="#">评论 2</a></li>
            <li class="icon-time"><a href="#">时间 2016-12-8</a></li>
          </ul>
        </div>
        <!--arrow_box end-->
      </li>
      <div class="post-nav-right"><p><a target="_blank" href="http://www.bokequ.com/blog/12/1.html" >点击阅读更多</a></p></div> 
    </ul>
    <!--bloglist end-->
    <aside>
      <div class="search">
        <form class="searchform" method="get" action="#">
          <input type="text" name="s" value="Search" onFocus="this.value=''" onBlur="this.value='Search'">
        </form>
      </div>
      <div class="viny">
        <dl>
          <dt class="art"><img src="images/13.jpg" alt="歌曲专辑"></dt>
          <dd class="icon-song"><span></span>我很快乐</dd>
          <dd class="icon-artist"><span></span>歌手:刘惜君</dd>
          <dd class="icon-album"><span></span>专辑:《我很快乐》</dd>
          <dd class="icon-like"><span></span><a href="#">喜欢</a></dd>
          <dd class="music">
            <audio src="http://www.bokequ.com/blog/12/images/kuaile.mp3" controls autoplay></audio>
          </dd>
          <!--也可以添加loop属性 音频加载到末尾时,会重新播放-->
        </dl>
      </div>
      <div class="tuijian">
        <h2>推荐文章</h2>
        <ol>
          <li><span><strong>1</strong></span><a target="_blank" href="http://www.bokequ.com/blog/summer/biye.html">广东省电子商务技师学院</a></li>
          <li><span><strong>2</strong></span><a target="_blank" href="http://www.bokequ.com/shuo/">浅蓝色小清新说说文章类织梦CMS个人博客模板</a></li>
          <li><span><strong>3</strong></span><a target="_blank" href="http://www.bokequ.com/blog/8/">花开花落—古典个人博客模板</a></li>
          <li><span><strong>4</strong></span><a target="_blank" href="http://www.bokequ.com/winter/">心情日记_心情语录随笔个人博客模板</a></li>
          <li><span><strong>5</strong></span><a target="_blank" href="http://www.bokequ.com/blog/sep/">九月.梦见夏天结束的样子个人博客</a></li>
          <li><span><strong>6</strong></span><a target="_blank" href="http://www.bokequ.com/time/">小清新个人博客主页模板 - 用照片记录时光</a></li>
          <li><span><strong>7</strong></span><a target="_blank" href="http://www.bokequ.com/blog/bozhao/index.html">广州博兆集团—五龙山庄拓展训练</a></li>
          <li><span><strong>8</strong></span><a target="_blank" href="http://www.bokequ.com/wo/">个人生活点滴记录博客</a></li>
          <li><span><strong>9</strong></span><a target="_blank" href="http://www.bokequ.com/blog/22/index.html">毕业了,一起看看青春期那些糟心大片!</a></li>
        </ol>
      </div>
      <div class="toppic">
        <h2>图文推荐</h2>
        <ul>
          <li><a href="#"><img src="images/k01.jpg">唯美雪景意境图片,唯美雪景意境图片壁纸!
            <p>点击阅读更多...</p>
            </a></li>
          <li><a href="#"><img src="images/10.jpg">浪漫唯美雪景图片_下雪浪漫唯美图片下载
            <p>点击阅读更多...</p>
            </a></li>
          <li><a href="#"><img src="images/k03.jpg">唯美人物雪景图片:冬天要是有雪才完美。
            <p>点击阅读更多...</p>
            </a></li>
          <li><a href="#"><img src="images/12.jpg">最美冬天雪景图片大全。
            <p>点击阅读更多...</p>
            </a></li>
          <li><a href="#"><img src="images/13.jpg">世上所谓幸福,就是一个笨蛋遇到一个傻瓜。
            <p>点击阅读更多...</p>
            </a></li>
        </ul>
      </div>
      <div class="clicks">
        <h2>热门点击</h2>
        <ol>
          <li><span><a href="#">慢生活</a></span><a href="http://www.bokequ.com/wo/share/">有一种思念,是淡淡的幸福,一个心情一行文字</a></li>
          <li><span><a href="#">爱情美文</a></span><a href="http://www.bokequ.com/wo/share/">励志人生-要做一个潇洒的女人</a></li>
          <li><span><a href="#">慢生活</a></span><a href="http://www.bokequ.com/wo/share/">女孩都有浪漫的小情怀——浪漫的求婚词</a></li>
          <li><span><a href="#">博客模板</a></span><a href="http://www.bokequ.com/wo/share/">Green绿色小清新的夏天-个人博客模板</a></li>
          <li><span><a href="#">女生个人博客</a></span><a href="http://www.bokequ.com/wo/share/">女生清新个人博客网站模板</a></li>
          <li><span><a href="#">Wedding</a></span><a href="http://www.bokequ.com/wo/share/">Wedding-婚礼主题、情人节网站模板</a></li>
          <li><span><a href="#">三栏布局</a></span><a href="http://www.bokequ.com/wo/share/">Column 三栏布局 个人网站模板</a></li>
          <li><span><a href="#">个人网站模板</a></span><a href="http://www.bokequ.com/wo/share/">时间煮雨-个人网站模板</a></li>
          <li><span><a href="#">古典风格</a></span><a href="http://www.bokequ.com/wo/share/">花气袭人是酒香—个人网站模板</a></li>
        </ol>
      </div>
      <div class="visitors">
        <h2>最新评论</h2>
        <dl>
          <dt><img src="images/s8.jpg" alt="看雪个人博客模板">
          <dt>
          <dd>DanceSmile
            <time>38分钟前</time>
          </dd>
          <dd>在 <a href="http://www.yangqq.com/jstt/bj/2013-07-28/530.html" class="title">如果要学习web前端开发,需要学习什么? </a>中评论:</dd>
          <dd>文章非常详细,我很喜欢.前端的工程师很少,我记得几年前yahoo花高薪招聘前端也招不到</dd>
        </dl>
        <dl>
          <dt><img src="images/s7.jpg" alt="看雪个人博客模板">
          <dt>
          <dd>yisa
            <time>2小时前</time>
          </dd>
          <dd>在 <a href="http://www.bokequ.com/blog/7/" class="title">>青春往事个人博客模板 - bokequ.com</a>中评论:</dd>
          <dd>我要下载个人博客模板</dd>
        </dl>
        <dl>
          <dt><img src="images/s6.jpg" alt="看雪个人博客模板">
          <dt>
          <dd>个人博客
            <time>12月7日</time>
          </dd>
          <dd>在 <a href="http://www.bokequ.com/wo/" class="title">如果个人博客网站再没有价值,你还会坚持吗? </a>中评论:</dd>
          <dd>博客色彩丰富,很是好看</dd>
        </dl>
        <dl>
          <dt><img src="images/s2.jpg" alt="看雪个人博客模板">
          <dt>
          <dd>小林博客
            <time>12月7日</time>
          </dd>
          <dd>在 <a href="http://www.bokequ.com/wo/" class="title">如果个人博客网站再没有价值,你还会坚持吗? </a>中评论:</dd>
          <dd>博客色彩丰富,很是好看</dd>
        </dl>
        <dl>
          <dt><img src="images/s5.jpg" alt="看雪个人博客模板">
          <dt>
          <dd>MAOLAI博客
            <time>12月7日</time>
          </dd>
          <dd>在 <a href="http://www.bokequ.com/wo/" class="title">如果个人博客网站再没有价值,你还会坚持吗? </a>中评论:</dd>
          <dd>博客色彩丰富,很是好看</dd>
        </dl>
      </div>
      <div class="flickr">
        <h2>最近访客</h2>
        <ul>
          <li><a href="#" rel="nofollw" title="梦想霞个人博客"><img src="images/s5.jpg"></a></li>
          <li><a target="_blank" href="http://www.xuanfengge.com/" rel="nofollw" title="轩枫阁"><img src="images/s2.jpg"></a></li>
          <li><a target="_blank" href="http://www.onmpw.com/index.html" rel="nofollw" title="迹忆博客"><img src="images/03.jpg"></a></li>
          <li><a target="_blank" href="http://m.bokequ.com/" rel="nofollw" title="草根站长目录"><img src="images/04.jpg"></a></li>
          <li><a href="#" rel="nofollw" title="艺小昔个人博客"><img src="images/05.jpg"></a></li>
          <li><a target="_blank" href="http://www.bokequ.com/wo/newstalk/" rel="nofollw" title="心情说说"><img src="images/06.jpg"></a></li>
          <li><a target="_blank" href="http://www.bokequ.com/wo/comic/" rel="nofollw" title="动漫资讯"><img src="images/s6.jpg"></a></li>
          <li><a href="#" rel="nofollw" title="超神学院"><img src="images/08.jpg"></a></li>
          <li><a target="_blank" href="http://www.bokequ.com/shuo/" rel="nofollw" title="唯美说说乐园"><img src="images/09.jpg"></a></li>
        </ul>
      </div>
    </aside>
  </div>
  <!--blogs end-->
</div>
<!--mainbody end-->
<footer>
  <div class="footer-bottom">
    <p>Copyright 2016 时间:大约在冬季 Design by <a href="http://www.bokequ.com">MAOLAI博客(bokequ.com)</a>  模板下载地址:更新中...</p>
  </div>
</footer>
<!-- jQuery仿腾讯回顶部和建议 代码开始 -->
<div id="tbox"> <a id="togbook" href="#"></a> <a id="gotop" href="javascript:void(0)"></a> </div>
<!-- 代码结束 -->
</body>
</html>

2、css样式

@charset "gb2312";
/* CSS Document */
* { margin: 0; padding: 0 }
body { font: 14px "宋体", "Arial Narrow", HELVETICA; color: #3F3E3C; line-height: 1.5; background:url(../images/bg1.jpg)}
img { border: 0; vertical-align: middle }
h1, h2, h3, h4, h5, h6 { font-weight: normal; }
h1 { font: 24px "微软雅黑", "Microsoft YaHei", Arial, Helvetica, sans-serif }
p { word-wrap: break-word }
ul, ol { list-style: none; }
a { color: #111; text-decoration: none; transition: All 1s ease; -webkit-transition: All 1s ease; -moz-transition: All 1s ease; -ms-transition: All 1s ease; -o-transition: All 1s ease; }
a:hover { color: #111; }
/* -----------------------nav 一级导航----------------- */
header {
	padding:133px 0 0 0;
	width:100%;
	height:380px;
	margin:auto;
	background:url(../images/top.jpg) center 0 scroll no-repeat;}
header img {
	float:left;
	margin:0 20px 0 66px;
	-webkit-animation:'flipInX' 1s ease 1s backwards;
	-moz-animation:'flipInX' 1s ease 1s backwards;
	-ms-animation:'flipInX' 1s ease 1s backwards;
	-o-animation:'flipInX' 1s ease 1s backwards;
	animation:'flipInX' 1s ease 1s backwards;
}
header h1 {
	font-size:16px;
	font-weight:normal;
	text-shadow:#fff 1px 1px 1px;
}
.b_nav{background:url(../images/menu_bg.png) 50% 0%;width:100%; margin-top:-160px;height:50px;}
header h1 a {
	color:#000
}
header h1 a:hover {
	text-decoration:underline
}
header p {
	margin:17px 0 0 0;
	text-shadow:#000 1px 1px 1px;
	color:#fff
}
#nav {
	width:100%;
	line-height:40px;
	height:40px;
	margin-top:-86px;
}
#nav ul {
	list-style:none;
	margin:auto;
	width:1030px
}
#nav ul li {
	float:left;
	width:100px;
	text-align:center;
	text-shadow:#333 1px 1px 1px;
}
#nav ul li a {
	display:block;
	color:#FFF;
	cursor:pointer;
	font-weight:bold;
}
#nav ul li a:hover {
	background:#6983d7;
	color:#FFF;
	font-weight:bold;
	border-radius:50px 0
}
#nav ul li a#nav_current {
	background:#6983d7;
	color:#FFF;
	font-weight:bold;
	border-radius:50px 0
}
#mainbody { width: 100%;clear: both; overflow: hidden; }
/* ---------------------info------------------------- */
.info { width: 1000px; margin:50px auto; overflow: hidden; clear: both }
/* 图片向上翻转的动画效果 */
.info figure { display: inline-block; width: 630px; height: 250px; position: relative; float: left; }
.info figcaption { padding: 20px; position: absolute; top: 20%; left: 0; background: rgba(153,153,153,.8); color: white; opacity: 0; -webkit-transition: opacity .75s ease-out; -moz-transition: opacity .75s ease-out; -o-transition: opacity .75s ease-out; transition: opacity .75s ease-out; }
.info figure:hover figcaption { opacity: 1; } /* 用opacity 设置鼠标放上去显示文字的效果 */
.info figcaption strong { display: block; line-height: 40px }
/* card */
.card { box-shadow: 0px 1px 0px rgba(255,255,255,.1), inset 0px 1px 1px rgba(0,0,0,.7); border-radius: 6px; background:#fff url(../images/quote-bg.png) no-repeat top right; width: 350px; float: right; height: 250px; overflow: hidden }
.card h1 { padding: 10px }
.card p:first-child { padding: 40px 0 0 40px } /* 结构性伪类选择符 选择第一个p标签,并且设置上、左距离是40px*/
.card p { padding: 0 0 0 40px; line-height: 28px; color: #111;}
.linkmore { margin: 15px 0 0 15px }
.linkmore li a { height: 50px; width: 50px; display: block; overflow: hidden; box-shadow: 0px 1px 0px rgba(255,255,255,.1), inset 0px 1px 1px rgba(0,0,0,.7); border-radius: 50%; float: left; margin: 0 6px; }
.linkmore li a:hover { opacity: 0.5; -webkit-transform: rotate(30deg); -ms-transform: rotate(30deg); -moz-transform: rotate(30deg); -o-transform: rotate(30deg); transform: rotate(30deg); }
.talk, .address, .email, .photos, .heart { background: url(../images/icons.png) no-repeat; }
.talk { background-position: 13px 18px }
.address { background-position: 12px -22px }
.email { background-position: 12px -60px }
.photos { background-position: 12px -137px }
.heart { background-position: 13px -99px }
/* --------------------博客列表-------------------- */
.blogs { width: 1000px; margin: 0 auto 20px; }
.bloglist {margin-top:-33px; width: 666px; float: left; }
.bloglist>li { border-right: #fff 2px solid; padding: 20px 0; }
.arrow_box { background: #fff; box-shadow: 0px 1px 0px rgba(255,255,255,.1), inset 0px 1px 1px rgba(0,0,0,.7); width: 630px; color: #b9b9b9; border-radius: 6px; position: relative }
.ti { width: 0px; height: 0px; border-style: solid; border-width: 0px 0 20px 22px; border-color: transparent transparent transparent #fff; position: absolute; left: 630px; top: 20px; }/* 三角形 */
.ci { width: 10px; height: 10px; border-radius: 50%; position: absolute; left: 658px; top: 16px; background: #fff; border: 2px solid #fff; } /* 圆形定义边框色与背景一致 */
.ci:hover { border: 2px solid #B9B9B9; }
.arrow_box h2.title { padding: 0 0 0 20px; font: 16px/50px "微软雅黑", "Microsoft YaHei", Arial, Helvetica, sans-serif }
.arrow_box h2 a:hover { padding-left: 20px }
.textinfo { overflow: hidden; }
.arrow_box img { width:200px; padding: 4px; float: left; -webkit-transition: All 1s ease; -moz-transition: All 1s ease; -ms-transition: All 1s ease; -o-transition: All 1s ease; border-radius: 4px; margin: 0 20px 20px; }
.arrow_box img:hover { opacity: 0.6; }
.arrow_box p {color:#111; line-height: 24px; padding: 0 20px 20px }
.details { background:#fafafa; border-radius: 0 0 6px 6px; padding: 0 10px }
.details li { line-height: 26px; display: inline; font-size:14px; margin-right: 10px; }
.details li a { color: #3F3E3C }
.details li a:hover { color: #933 }
.icon-time, .likes, .comments { background: url(../images/icons.png) no-repeat }
.icon-time { background-position: 0 -208px; padding: 0 0 0 18px; }
.likes, .comments { float: right; padding: 0 0 0 14px; }
.likes { background-position: 0 -240px; }
.comments { background-position: 0 -220px; }
.post-nav-right{height:68px}
.post-nav-right p{text-align:center;line-height:60px;font-size:16px;}
.post-nav-right a{
    padding: 10px 10px;
    color: #222;
    background: #fff;
    border-radius: 3px;}
/*-------------------aside侧边栏--------------------------*/
aside { width: 310px; float: right; margin:-12px 0; }
aside h2{ font-weight:bold;font-size: 16px; margin-bottom: 10px;color: #222 }
aside div { box-shadow: 0px 1px 0px rgba(255,255,255,.1), inset 0px 1px 1px rgba(0,0,0,.7); border-radius: 6px; padding: 15px; background: #fff; margin-bottom: 20px; overflow: hidden; }
.tuijian li, .clicks li { white-space: nowrap; text-overflow: ellipsis; overflow: hidden }
.tuijian li a:hover { padding-left: 10px }
.tuijian li span:before { content: "0"; }/* 数字列表前面统一加0  */
.tuijian li span { margin-right: 10px; font-size: 14px; font-family: "微软雅黑"; }
.tuijian li:nth-child(-n+3) span { width: 39px; color: #999 } /* 选择从第3个开始倒数也就是第三个前面的 */
.tuijian li:nth-child(-n+3) strong { font-size: 24px; font-weight: normal; }
.tuijian li:first-child span { color: #f8490b; } /* 选择第一个 */
.tuijian li:nth-child(n+3) { line-height: 24px } /* 选择从第3个开始往后数 */
.tuijian li:nth-child(4) { margin: 5px 0 0 0 } /* 选择第四个 */
/* 图文推荐 */
.toppic li{margin:10px 0;}
.toppic li img { width:100px; float: left; margin-right: 10px; }
.toppic ul li:nth-child(2) { margin: 15px 0; }
.toppic ul li a { display: block; width: 100%; clear: both; overflow: hidden }
.toppic li p { color: #B5783E; padding-left: 110px; margin-top: 5px; }
.toppic li:first-child p { background-position: 90px -263px; }
.toppic li:nth-child(2) p { background-position: 90px -283px; }
.toppic li:last-child p { background-position: 90px -301px; }
/* 热门点击 */
.clicks li { line-height: 24px; }
.clicks li span:before { content: "【"; }
.clicks li span:after { content: "】"; }
.clicks li span a { padding: 0 5px; color: #366 }
.clicks li a:hover { text-decoration: underline }
/* search */
.searchform { overflow: hidden; padding: 10px; }
.searchform input { background:#fdfdfd url(../images/icons.png) no-repeat 3px -318px; border: 1px solid #111; width: 220px; line-height: 30px; color: #b9b9b9; padding-left: 30px; }
/* music */
.viny dl dd { color: #b9b9b9; line-height: 24px; }
.art { background: url(../images/vinyl.png) no-repeat left; width: 130px; float: left; background-size: 120px; }
.viny .art img { width: 90px; height: 90px; margin-left: 11px }
.viny dd span { width: 12px; height: 24px; margin-right: 7px; float: left; display: block; }
.icon-song span, .icon-artist span, .icon-album span, .icon-like span { background: url(../images/icons.png) no-repeat }
.icon-song span { background-position: -33px -344px }
.icon-artist span { background-position: -16px -344px }
.icon-album span { background-position: 0 -344px }
.icon-like span { background-position: -1px -299px; }
.icon-like a { color: #B5783E }
.icon-like a:hover { color: #FFF; text-decoration: underline }
.music audio { width: 100%; padding-top: 10px }
/* 最新评论 */
.visitors dl { display: block; overflow: hidden; margin-bottom: 12px }
.visitors dd { line-height: 22px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden }
.visitors dd:last-child { color: #6A9150; }
.visitors time { color: #066; margin-left: 10px }
.visitors dt { float: left; }
.visitors dt img { width: 67px; height: 67px; margin-right: 10px; }
/* 最近访客 */
.flickr ul li { margin: 0 11px 11px 0; float: left; background: #000; }
.flickr ul li img { width: 67px; height: 67px; border: #111 solid 1px; }
.flickr ul li img:hover { opacity: 0.6 }
/* --------------------------footer----------------------- */
.footer-bottom {margin-top:38px;overflow: hidden; }
.footer-bottom p { font-size:14px;text-align:center;color:#fff; width: 1000px; margin: 0 auto; padding: 10px 0; }

看雪时间轴个人博客模板代码演示http://www.bokequ.com/blog/12/