《CSS样式及页面布局》实验指导
一、实验目标
本实验目标为掌握css样式的定义方法及使用,熟练应用css和html标签进行页面设计和布局。支撑专业核心能力的培养。
二、实验要求
- 掌握内联样式、嵌入样式、外部样式
- 掌握通用选择器、类型选择器、类选择器、Id选择器的使用
- 掌握盒子模型
- 掌握div+css布局
三、实验内容
CSS内联样式、嵌入样式、外部样式定义与使用;
通用选择器、类型选择器、类选择器、Id选择器的使用;
Css盒子模型样式;
Div+css布局;
四、主要仪器设备
硬件: PC电脑
软件: Visual Studio Code/WebStorm/HBuilder
五、考核方式及要求
提交实验报告、源代码
六、实验内容和步骤
使用DIV+CSS布局完成对一个手机网页的布局
1、用前端开发环境创建main.html,样式表采用外部链入CSS文件
2、设置视口属性,在head中添加标记
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
3、使用div+CSS完成布局;距离单位根据设计图测量值换算成rem,较窄的border仍保持使用px,rem即元素px值相对于rootFontSize px值的比值,换算公式:
rootFontSize = 100
rem距离 = 元素px距离 / rootFontSize
使用JavaScript动态设置HTML文档rootFontSize,假设设计图的rootFontSize为100,若真实屏幕宽度与设计文档不同,则执行以下代码进行换算,以保证网页在不同尺寸屏幕中都能最大限度的还原设计图的尺寸比例。
<script type="text/javascript">
function setRootFontSize(){
var rootHtml = document.documentElement;
var rem = rootHtml.clientWidth / (1080 / 100); //1080为设计图px宽度
rootHtml.style.fontSize = rem + "px";
}
setRootFontSize(); //网页首次载入时执行一次
window.addEventListener("resize", setRootFontSize, false); //网页大小改变时执行
window.addEventListener("orientationchange", setRootFontSize, false); //横屏切换时执行
</script>
4、网页的头部和底部(选做)分别固定显示在屏幕顶部和底部,将样式表position属性的值设为fixed,top属性设为0px即置顶,bottom属性设为0px即置底。
页码标题、文本框、注册按钮的宽度和网页总体宽度为自适应,其他所有宽度均设为固定长度;颜色和网页布局时涉及的各个尺寸需要自己测量和换算。
5、文本框和密码框中文字的颜色为黑色,设计图中显示的是默认的占位符的颜色,将文本框的placeholder属性值设置为图中的文字即可看到效果。
七、实验结果
1、编写实验报告:
实验报告中写上网页制作的步骤,并附上重要步骤及结果的截图。
2、提交实验结果:
序号 | 文件名 | 说明 |
1 | main.html | 手机网页文件 |
2 | main.css | CSS样式表 |
2 | main_config1.png | |
3 | main_config2.png | |
4 | main_home1.png | |
5 | main_home2.png | |
6 | sub_back.png | |
7 | sub_more.png | |
8 | 实验2报告.docx | 实验报告 |
将HTML文件、CSS文件和图片打包,与报告文件分开上传,报告文件不要压缩
html:
<!DOCTYPE html>
<html lang="en" style="font-size:200px">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<script type="text/javascript">
function setRootFontSize(){
var rootHtml = document.documentElement;
var rem = rootHtml.clientWidth / (1080 / 100); //1080为设计图px宽度
rootHtml.style.fontSize = rem + "px";
}
setRootFontSize(); //网页首次载入时执行一次
window.addEventListener("resize", setRootFontSize, false); //网页大小改变时执行
window.addEventListener("orientationchange", setRootFontSize, false); //横屏切换时执行
</script>
<title>实验2</title>
<link rel="stylesheet" href="./02.css">
</head>
<body>
<div id="header">
<div class="header-left"> </div>
<div class="header-right"> </div>
<div class="header-center">用户注册</div>
</div>
<div id="area1">
<div class="area1-left">用户名</div>
<div class="area1-center"><input type="text" placeholder="请输入用户名" class="yonghuming" ></div>
</div>
<div id="area2">
<div class="area2-left">手机号</div>
<div class="area2-center"><input type="text" placeholder="请输入手机号" class="shoujihao" ></div>
<div class="area2-right">发送验证码</div>
</div>
<div id="password">
<div class="password-left">密码</div>
<div class="password-center"><input type="text" class="mima" ></div>
</div>
<div id="check_the_password">
<div class="check_the_password-left">确认密码</div>
<div class="check_the_password-center"><input type="text" class="querenmima" ></div>
</div>
<div id="zhuce">注册</div>
<div id="other">
<div class="other-left">已有账号</div>
<div class="other-right">更换手机号</div>
</div>
<div id="dxt">
<div id="bottompicture">
<div class="bottompicture-left"> </div>
<div class="bottompicture-right"> </div>
</div>
<div id="bottomwriting">
<div class="bottomwriting-left">首页</div>
<div class="bottomwriting-right">设置</div>
</div>
<div id="supplyment"> </div>
</div>
</body>
</html>
css:
body{
margin:0px;
}
#header{
background: #e66d05;
overflow: hidden;
position: fixed;
top: 0rem;
width: 100%;
}
.header-left{
float: left;
width: 1.15rem;
height: 1.32rem;
background-image: url("img/sub_back.png");
background-repeat: no-repeat;
background-position: 0.46rem 0.37rem;/*left top*/
background-size: 0.55rem 0.55rem;
}
.header-left img{
width: 0.58rem;
height: 0.55rem;
}
.header-center{
color: #ffffff;
font-size: 0.58rem;
line-height: 0.58rem;
padding: 0.37rem 0rem 0.37rem 0rem;
text-align: center;
margin: 0rem 1.15rem 0rem 1.15rem;
}
.header-right{
float: right;
width: 1.15rem;
height: 1.32rem;
background-image: url("img/sub_more.png");
background-repeat: no-repeat;
background-position: 0.1rem 0.37rem;/*left top*/
background-size: 0.55rem 0.55rem;
}
#area1{
width: 10.80rem;
overflow: hidden;
}
.area1-left{
float: left;
font-size: 0.47rem;
color: #5f5f5f;
line-height: 0.47rem;
text-align: left;
padding: 0.62rem 0.76rem 0.13rem 0.47rem;
margin-top: 1.32rem;
}
.area1-center{
float: left;
width: 7.65rem;
height: 0.6rem;
padding: 0.63rem 0rem 0rem 0rem;
margin-top: 1.32rem;
}
.yonghuming{
float:left;
height: 0.45rem;
width: 7.65rem;
font-size: 0.47rem;
line-height: 0.47rem;
border: 0.04rem solid #a1a1a1;
border-top: 0rem;
border-left: 0rem;
border-right: 0rem;
padding: 0rem 0rem 0.1rem 0.11rem;
color: #a1a1a1;
}
#area2{
width: 10.80rem;
overflow: hidden;
}
.area2-left{
float: left;
font-size: 0.47rem;
color: #5f5f5f;
line-height: 0.47rem;
text-align: left;
padding: 0.42rem 0.76rem 0.13rem 0.47rem;
}
.area2-center{
float: left;
width: 4rem;
height: 0.6rem;
padding: 0.42rem 0rem 0rem 0rem;
}
.shoujihao{
float:left;
height: 0.45rem;
width: 3.8rem;
font-size: 0.47rem;
line-height: 0.47rem;
border: 0.04rem solid #a1a1a1;
border-top: 0rem;
border-left: 0rem;
border-right: 0rem;
padding: 0rem 0rem 0.1rem 0.11rem;
color: #a1a1a1;
}
.area2-right{
float: left;
width: 3.5rem;
font-size: 0.38rem;
line-height: 0.38rem;
color: #eb6d06;
padding: 0.5rem 0rem 0.14rem 0.23rem;
}
#password{
width: 10.80rem;
overflow: hidden;
}
.password-left{
float: left;
font-size: 0.47rem;
color: #5f5f5f;
line-height: 0.47rem;
text-align: left;
padding: 0.42rem 0.76rem 0.13rem 0.47rem;
}
.password-center{
float: left;
width: 7.65rem;
height: 0.6rem;
padding: 0.42rem 0rem 0rem 0.45rem;
}
.mima{
float:left;
height: 0.45rem;
width: 7.65rem;
font-size: 0.47rem;
line-height: 0.47rem;
border: 0.04rem solid #a1a1a1;
border-top: 0rem;
border-left: 0rem;
border-right: 0rem;
padding: 0rem 0rem 0.1rem 0.11rem;
color: #a1a1a1;
}
#check_the_password{
width: 10.80rem;
overflow: hidden;
}
.check_the_password-left{
float: left;
font-size: 0.47rem;
color: #5f5f5f;
line-height: 0.47rem;
text-align: left;
padding: 0.42rem 0.27rem 0.13rem 0.47rem;
}
.check_the_password-center{
float: left;
width: 7.65rem;
height: 0.6rem;
padding: 0.42rem 0rem 0rem 0rem;
}
.querenmima{
float:left;
height: 0.45rem;
width: 7.65rem;
font-size: 0.47rem;
line-height: 0.47rem;
border: 0.04rem solid #a1a1a1;
border-top: 0rem;
border-left: 0rem;
border-right: 0rem;
padding: 0rem 0rem 0.1rem 0.11rem;
color: #a1a1a1;
}
#zhuce{
font-size: 0.52rem;
line-height: 0.52rem;
text-align: center;
color:#fffdff;
background-color: #e66d05;
padding: 0.32rem 0rem 0.28rem 0rem;
margin: 0.68rem 0.4rem 0rem 0.40rem;
}
#other{
width: 10.80rem;
overflow: hidden;
color: #5a5a5a;
}
.other-left{
float: left;
font-size: 0.33rem;
padding: 0.31rem 0rem 0rem 0.48rem;
}
.other-right{
float: right;
font-size: 0.33rem;
padding: 0.31rem 0.52rem 0rem 0rem;
}
#bottompicture{
background-color: #e66d05;
width: 10.80em;
overflow: hidden;
height: 0.76rem;
}
.bottompicture-left{
float: left;
width: 1rem;
height: 0.76rem;
background-image: url("img/main_home2.png");
background-repeat: no-repeat;
background-position: 0.23rem 0.16rem;
background-size: 0.55rem 0.55rem;
background-color: #ffffff;
margin: 0rem 0rem 0rem 0.27rem;
}
.bottompicture-right{
float: right;
width: 0.8rem;
height: 1rem;
background-image: url("img/main_config1.png");
background-repeat: no-repeat;
background-position: 0.2rem 0.14rem;
background-size: 0.55rem 0.55rem;
margin: 0rem 0.27rem 0rem 0rem;
}
#bottomwriting{
background-color: #e66d05;
width: 10.80em;
overflow: hidden;
}
.bottomwriting-left{
float: left;
width: 1rem;
font-size: 0.31rem;
line-height: 0.31rem;
color: #e66d05;
background-color: #ffffff;
margin: 0rem 0rem 0rem 0.27rem;
text-align: center;
padding-bottom: 0.07rem;
}
.bottomwriting-right{
float: right;
color: #ffffff;
width: 0.7rem;
font-size: 0.31rem;
line-height: 0.31rem;
text-align: center;
padding: 0rem 0.25rem 0rem 0rem;
}
#supplyment{
background-color:#e66d05 ;
height: 0.2rem;
}
#dxt{
position: fixed;
bottom: 0rem;
}