本帖最后由 小江哥 于 2018-5-18 16:09 编辑
今日任务
使用CSS完成网站首页的美化
使用CSS完成网站注册页面的美化
使用JS完成简单的数据校验
使用JS完成图片轮播效果
1.1上次课的内容回顾:
HTML:
* HTML的概述:
* HTML:Hyper Text Markup Language.
* HTML就是由一组标签所组成的.
* HTML的字体标签:
* <font>标签:
* 属性:color,size,face
* HTML的排版标签:
* h标签:标题标签.
* p标签:段落标签.
* b标签:加粗标签.
* i标签:斜体标签.
* u标签:下划线标签.
* br标签:换行.
* hr标签:水平线.
* HTML的图片标签:
* img标签:
* 属性:
* src属性:图片的路径.
* 相对路径: ./ 代表当前目录 ../上一级目录
* width,height,alt.
* HTML的超链接标签:
* a标签:
* 属性:
* href:链接的路径.
* target:链接打开的方式. _self,_blank,_parent
* HTML的列表标签:
* 无序列表:<ul>
* 有序列表:<ol>
* HTML的表格标签:
* table标签:
* tr标签:表格的行.
* td标签:表格的列.
* HTML的表单标签:(*****)
* form标签:
* action属性:表单提交的路径
* method属性:表单的提交的方式.
* GET和POST:
* GET:地址栏上会显示提交的数据的信息,大小限制.
* POST:地址栏不会显示提交的数据的信息,没有大小限制.
* <input>
* type=”text”:文本框
* type=”password”:密码框.
* type=”radio”:单选按钮.
* type=”checkbox”:复选框.
* type=”file”:文件上传.
* type=”hidden”:隐藏字段.
* type=”submit”:提交按钮.
* type=”reset”:重置按钮.
* type=”button”:普通按钮.
* type=”image”:图片按钮.
* <select>:下拉列表.
* <textarea>:文本区
* HTML的框架标签:
* <frameset>
* <frame>
1.2案例一:使用DIV+CSS方式重新布局网站的首页.
1.2.1需求:
网站首页的设计:采用DIV+CSS的方式完成.
[AppleScript] 纯文本查看 复制代码 【CSS的引入的方式】
行内样式:直接在HTML的元素上使用style属性设置CSS.
<h1 style="color:red;font-size:200px ;">标题</h1>
页面内样式:在HTML的<head>标签中使用<style>标签设置CSS.
<style>
h1{
color:blue;
font-size: 40px;
}
</style>
外部样式:单独定一个.css的文件.在HTML中引入该CSS文件.
<link href="../../css/demo1.css" rel="stylesheet" type="text/css" />
[AppleScript] 纯文本查看 复制代码 元素选择器:
div{
border:1px solid blue;
width:40px;
height:45px;
}
ID选择器:
#d1{
border:2px solid red;
}
类选择器:
.divClass{
border:2px solid yellow;
}
[AppleScript] 纯文本查看 复制代码 案例:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
.divClass{
border:1px solid blue;
width:200px;
height:220px;
}
#d1{
float:left;
}
#d2{
float:left;
}
#d3{
float:left;
}
.clear{
clear:both;
}
</style>
</head>
<body>
<div id="d1" class="divClass">DIV1</div>
<div id="d2" class="divClass">DIV2</div>
<div id="d3" class="divClass">DIV3</div>
<div class="clear"></div>
<div id="d4" class="divClass">DIV4</div>
</body>
</html>
1.2.2.2步骤分析:
【步骤一】创建一个首页的HTML文件
【步骤二】创建一个整体的DIV元素.
【步骤三】创建每个部分的DIV元素.
【步骤四】为每个部分填充属于自己的那块内容.
1.2.3代码实现:
[AppleScript] 纯文本查看 复制代码 <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>首页</title>
<style>
#bodyDiv{
border:1px solid blue;
width:90%;
}
.logoDiv{
border:1px solid blue;
width:33%;
float:left;
height:50px;
}
.clear{
clear:both;
}
#menuDiv{
width:100%;
height:50px;
border:1px solid blue;
background-color: black;
}
#imgDiv{
width:100%;
border:1px solid blue;
}
#menuDiv a{
font-size: 20px;
color: white;
}
.productClass{
width:100%;
border:1px solid blue;
}
.contentClass{
width:100%;
border:1px solid blue;
}
.contentClass font{
font-size: 30px;
color: black;
}
</style>
</head>
<body>
<!-- 整体的DIV -->
<div id="bodyDiv">
<!-- logo的DIV -->
<div>
<div class="logoDiv">
<img src="../img/logo2.png" height="48">
</div>
<div class="logoDiv">
<img src="../img/header.png" height="48">
</div>
<div class="logoDiv">
<a href="">登录</a>
<a href="">注册</a>
<a href="">购物车</a>
</div>
<div class="clear"></div>
</div>
<!-- Menu的DIV -->
<div id="menuDiv">
<a href="">首页</a>
<a href="">电脑办公</a>
<a href="">手机数码</a>
<a href="">烟酒糖茶</a>
</div>
<!-- 图片滚动的DIV -->
<div id="imgDiv">
<img src="../img/1.jpg" width="100%">
</div>
<!-- 热门商品的DIV -->
<div class="productClass">
<!-- 文字部分的DIV -->
<div class="contentClass">
<font>热门商品</font><img src="../img/title2.jpg">
</div>
<!-- 商品部分的DIV -->
<div style="width:100%;border:1px solid blue;">
<div style="width:15%;height: 460px;border:1px solid blue;float:left;">
<img src="../img/big01.jpg" width="100%" height="100%">
</div>
<div style="width:84%;height: 460px;border:1px solid blue;float:left;">
<div>
<div style="border:1px solid blue;width:48%;float:left;height:228px;">
<img src="../img/middle01.jpg" width="100%" height="100%">
</div>
<div style="border:1px solid blue;width:16%;float:left;height:228px;">
<img src="../img/small03.jpg">
</div>
<div style="border:1px solid blue;width:16%;float:left;height:228px;">
<img src="../img/small03.jpg">
</div>
<div style="border:1px solid blue;width:16%;float:left;height:228px;">
<img src="../img/small03.jpg">
</div>
</div>
<div>
<div style="border:1px solid blue;width:16%;float:left;height:228px;">
<img src="../img/small03.jpg">
</div>
<div style="border:1px solid blue;width:16%;float:left;height:228px;">
<img src="../img/small03.jpg">
</div>
<div style="border:1px solid blue;width:16%;float:left;height:228px;">
<img src="../img/small03.jpg">
</div>
<div style="border:1px solid blue;width:16%;float:left;height:228px;">
<img src="../img/small03.jpg">
</div>
<div style="border:1px solid blue;width:16%;float:left;height:228px;">
<img src="../img/small03.jpg">
</div>
<div style="border:1px solid blue;width:16%;float:left;height:228px;">
<img src="../img/small03.jpg">
</div>
</div>
</div>
</div>
</div>
<!-- 广告的DIV -->
<div style="width:100%;border:1px solid blue;">
<img src="../img/ad.jpg" width="100%" height="80">
</div>
<!-- 最新商品的DIV -->
<div class="productClass">
<!-- 文字部分的DIV -->
<div class="contentClass">
<font>最新商品</font><img src="../img/title2.jpg">
</div>
<!-- 商品部分的DIV -->
<div style="width:100%;border:1px solid blue;">
<div style="width:15%;height: 460px;border:1px solid blue;float:left;">
<img src="../img/big01.jpg" width="100%" height="100%">
</div>
<div style="width:84%;height: 460px;border:1px solid blue;float:left;">
<div>
<div style="border:1px solid blue;width:48%;float:left;height:228px;">
<img src="../img/middle01.jpg" width="100%" height="100%">
</div>
<div style="border:1px solid blue;width:16%;float:left;height:228px;">
<img src="../img/small03.jpg">
</div>
<div style="border:1px solid blue;width:16%;float:left;height:228px;">
<img src="../img/small03.jpg">
</div>
<div style="border:1px solid blue;width:16%;float:left;height:228px;">
<img src="../img/small03.jpg">
</div>
</div>
<div>
<div style="border:1px solid blue;width:16%;float:left;height:228px;">
<img src="../img/small03.jpg">
</div>
<div style="border:1px solid blue;width:16%;float:left;height:228px;">
<img src="../img/small03.jpg">
</div>
<div style="border:1px solid blue;width:16%;float:left;height:228px;">
<img src="../img/small03.jpg">
</div>
<div style="border:1px solid blue;width:16%;float:left;height:228px;">
<img src="../img/small03.jpg">
</div>
<div style="border:1px solid blue;width:16%;float:left;height:228px;">
<img src="../img/small03.jpg">
</div>
<div style="border:1px solid blue;width:16%;float:left;height:228px;">
<img src="../img/small03.jpg">
</div>
</div>
</div>
</div>
</div>
<!-- 页脚的DIV -->
<div style="width:100%;border:1px solid blue;">
<img src="../img/footer.jpg" width="100%">
</div>
<!-- 友情链接及版权的DIV -->
<div style="width:100%;border:1px solid blue;">
<center>
关于我们 联系我们 招贤纳士 法律声明 友情链接 支付方式 配送方式 服务声明 广告声明 <br/>
Copyright © 2005-2016 传智商城 版权所有
</center>
</div>
</div>
</body>
</html>
[AppleScript] 纯文本查看 复制代码 1.2.4总结:
【CSS的其他选择器】
属性选择器:
<style>
input[type="text"]{
background-color: red;
}
</style>
后代选择器:
div span 查找的是所有div中的所有的span元素.
h1 strong{
color:red;
}
<h1>
This is <strong>very</strong> <strong>very</strong> important.
</h1>
<h1>This is
<strong>very</strong>
<em>really
<strong>very</strong>
</em>
important.
</h1>
子元素选择器:
div > span找这个div中的第一层级的span元素.
h1 > strong{
color:red;
}
<h1>
This is <strong>very</strong> <strong>very</strong> important.
</h1>
<h1>This is
<strong>very</strong>
<em>really
<strong>very</strong>
</em>
important.
</h1>
并列选择器:
选择器,选择器{
}
1.3.2.2步骤分析:
【步骤一】创建一个html页面
【步骤二】创建一个整体的DIV
【步骤三】在整体DIV中创建5个DIV.
【步骤四】为每个DIV添加所属的内容.
1.3.3代码实现:
[AppleScript] 纯文本查看 复制代码 <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>注册页面</title>
<style>
div{
border:1px solid blue;
}
.bodyDiv{
width:90%;
}
.bodyDiv > div{
width:100%;
}
.logoDiv{
width:33%;
height:50px;
float:left;
}
.clear{
clear:both;
}
ul li{
display:inline;
}
</style>
</head>
<body>
<!--整体DIV-->
<div class="bodyDiv">
<div>
<div class="logoDiv">
<img src="../img/logo2.png" height="50"/>
</div>
<div class="logoDiv">
<img src="../img/header.png" height="50"/>
</div>
<div class="logoDiv" style="margin-top:0px;padding-top:10px;height:40px;">
<a href="">登录</a>
<a href="">注册</a>
<a href="">购物车</a>
</div>
<div class="clear"></div>
</div>
<div style="height:50px;background-color: black;color:white;font-size: 20px;">
<ul >
<li>首页</li>
<li>首页</li>
<li>首页</li>
<li>首页</li>
</ul>
</div>
<div style="height:500px;background-image: url(../img/regist_bg.jpg);">
<div style="border:5px solid gray;background-color:white;position:absolute;left:350px;top:160px;width:600px;">
<form>
<table border="0" width="100%" cellspacing="15">
<tr>
<td>用户名</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>密码</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td>确认密码</td>
<td><input type="password" name="repassword"></td>
</tr>
<tr>
<td>性别</td>
<td><input type="radio" name="sex" value="男">男<input type="radio" name="sex" value="女">女</td>
</tr>
<tr>
<td>籍贯</td>
<td>
<select name="province">
<option>-请选择-</option>
</select>
<select name="city">
<option>-请选择-</option>
</select>
</td>
</tr>
<tr>
<td>爱好</td>
<td>
<input type="checkbox" name="hobby" value="篮球" />篮球
<input type="checkbox" name="hobby" value="足球" />足球
<input type="checkbox" name="hobby" value="排球" />排球
<input type="checkbox" name="hobby" value="羽毛球" />羽毛球
</td>
</tr>
<tr>
<td>邮箱</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="注册"></td>
</tr>
</table>
</form>
</div>
</div>
<div>
<img src="../img/footer.jpg" width="100%"/>
</div>
<div>
<center>
关于我们 联系我们 招贤纳士 法律声明 友情链接 支付方式 配送方式 服务声明 广告声明 <br/>
Copyright © 2005-2016 传智商城 版权所有
</center>
</div>
</div>
</body>
</html>
[AppleScript] 纯文本查看 复制代码 <script>
// alert("Hello!");
function checkForm(){
// 获得文本框的值:
var username = document.getElementById("username").value;
// var val = username.value;
// alert(username);
if(username == ""){
alert("用户名不能为空!");
return false;
}
// 校验密码:
var password = document.getElementById("password").value;
if(password == ""){
alert("密码不能为空");
return false;
}
// 校验确认密码:
var repassword = document.getElementById("repassword").value;
if(repassword != password){
alert("两次密码输入不一致!");
return false;
}
// 校验邮箱:
var email = document.getElementById("email").value;
// JS校验正则表达式就有两个方法:String对象中的match方法,一个是正则对象中的test方法.
// str.match("正则表达式"); 正则.test("字符串");
if(!/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/.test(email)){
alert("邮箱格式不正确!");
return false;
}
}
</script> [mw_shl_code=applescript,true]
|