今日内容:
-
标准流
-
浮动流
-
定位流
-
JavaScript概念介绍
-
JavaScript的引入
-
ECMAScript
-
BOM
-
DOM
标准流
>1.HTML标签被分为两种类型,一种是块级标签(独占一行,能够设置宽高),另外一种是行级标签(不独占一行,不能设置宽高)
>
>2.这两种类型的标签都是按照标准流的方式进行渲染加载的(排列),行级标签从左到右加载,块级元素从上到下加载。
display
display属性:常用取值 inline(行级元素)、block(块级元素)、inline-block(行内块元素),none(隐藏,不占空间)
浮动流
1.浮动流,设置标签的属性float,它能够让元素向左或者向右进行浮动,浮动流只能是左右浮动没有上下浮动,如果元素按照浮动流渲染,那么该元素会脱离标准流,在浮动流中没有行级元素和块级元素之说。但是都可以设置宽高。
2.在标准流的加载方式下,如果更改标准流,那么该元素后面的元素会相应的顶上来。
3.如果按照浮动流进行加载,在浮动流加载的情况下,元素是之间排列是按照紧邻排列,中间没有空隙。
浮动流一般加载在标准流的上面
clear
设置clear属性,能够使元素在浮动的过程中不去紧贴其他标签,只能影响自己,不能影响其他的元素
定位流
##### 相对定位
不会脱离标准流。相对于在标准流的位置进行位置移动,所以下面的元素不会顶上来。
属性position设置值为relative,进行位置移动结合属性top、left、right、bottom进行空间位置移动。
绝对定位
会脱离标准流,所以下面的元素会顶上来,相对于在标准流的位置上进行空间移动
设置属性position为absolute,同样也需要结合top、left、right、bottom四个属性搭配使用
如果它的父元素或者祖先元素都没有设置定位流(相对定位、绝对定位、固定定位),绝对定位相对于body进行定位。
如果父元素或者祖先元素有定位流,绝对定位相对于父元素或者祖先元素(就近原则)。
在绝对定位中,也是不区分块级元素和行级元素,但是都可以设置宽高。
定位流中,一般我们采用父相子绝
固定定位
固定定位也会脱离标准流,设置position为fixed,依然需要借助于四个方向属性top、left、right、bottom进行空间移动
不区分行级元素和块级元素,和绝对定位一样,唯一的不同它不会随着滚动条的滚动而发生移动。
z-index
z-index 可以改变定位流中的前后加载顺序。
-
定位流中有以下规律
1.默认情况下定位流会覆盖标准流
2.默认情况下后面的会覆盖前面的
3.定位流中设置z-index,是一个整数数值,谁的大谁就在上面
如果父元素设置z-index,子元素的z-index就会失效,谁的父元素大,谁就显示上方(从父原则)
JavaScript概念的介绍
>JavaScript是web上的一门编程语言,用于和用户进行交互,不需要进行编译,嵌套在html文件中由浏览器引擎加载执行,和Java没有大的联系。
JavaScipt的组成
-
核心(ECMAScirpt)语法,包括基本的流程控制,运算符,数据类型,数组,对象,类,接口等。
-
浏览器对象模型(BOM) browser object model,主要是操作当前浏览器窗口的内容,如页面的跳转和页面刷新等动作。
-
文档对象模型(DOM) document object model,主要是操作html文件中的具体内容(页面元素内容),如页面中有一个div,动态给div添加高宽,添加背景图像,植入需要的文本内容,让div隐藏起来。
JavaScript代码的引入
-
内嵌式
在html文档中,将相关的js代码直接放在标签<script>中,至于位置可以放在html标签中也就可以放在body中。
-
外联式
首先需要在html文件的外面独立创建一个js文件,文件的扩展名为xxx.js,在html文件中通过script标签进行引入,至于引入的位置没有要求。(head和body都可以)。
备注:1.引入的位置虽然随意,但是有一个加载顺序的问题,如果js代码存放在head标签中,那么会首先加载js代码,如果js代码中对页面元素内容有控制,则没有效果;如果js代码存放在body标签中并且存放在body页面元素的下面,那么浏览器会首先加载body中的页面元素,再去加载js代码,此时如果js对页面元素有控制,则有效果。
2.如果引入的不是直接对页面元素控制的技术代码,而是第三方js插件,那么一般情况下需要先引入(浏览器先加载),才能进行后续依赖开发。
ECMAScript核心语法
>在核心语法中,语法的特征基本和java一致,个别有点区别。
声明变量的时候,不需要指定变量的数据类型,通用写法,使用var,比如你想声明一个整数类型的变量 var num = 123;
编译器代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>标准流加载</title>
<style type="text/css">
*{
box-sizing: border-box;
margin: 0;
padding: 0;
}
a{
display: block;
height: 100px;
width: 200px;
}
div{
display: inline-block;
height: 100px;
width: 200px;
}
h1{
display: none;
}
</style>
</head>
<body>
<a style="border: 1px solid red;">百度一下</a>
<span style="border: 1px solid black;">有求必应</span>
<!-- 块级标签 -->
<div style="border: 1px solid green;">
我是一个块级标签div
</div>
<span>我是第二个span标签元素</span>
<h1 style="border: 1px solid purple;">我是一个大标题</h1>
<p style="border: 1px solid blue;">我也是一个块级标签p段落</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>浮动流</title>
<style>
*{
box-sizing: border-box;
}
div{
height: 300px;
width: 500px;
border: 1px solid red;
}
#div01{
background-color: green;
float: left;
}
#div02{
background-color: yellow;
/* float: left; */
}
</style>
</head>
<body>
<div id="div01">我是第一个div</div>
<div id = "div02">
我是第二个div
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>浮动流操作2</title>
<style type="text/css">
a{
float: left;
margin-right: 30px;
margin-top:20px;
font-size: 13px;
}
#div01{
float: left;
}
#div02{
float: right;
}
</style>
</head>
<body>
<div id="div01">
<a>新闻</a>
<a>hao123</a>
<a>地图</a>
<a>视频</a>
<a>贴吧</a>
<a>学术</a>
<a>更多</a>
</div>
<div id="div02">
<a>设置</a>
<a>登录</a>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>浮动流操作3</title>
<style type="text/css">
div{
width: 200px;
height: 200px;
}
#box01{
float: right;;
background-color: red;
}
#box02{
float: left;
background-color: green;
clear: both;
}
#box03{
float: left;
background-color: blue;
clear: both;
}
</style>
</head>
<body>
<div id="box01"></div>
<div id="box02"></div>
<div id="box03"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>相对定位</title>
<style type="text/css">
div{
height: 200px;
width: 200px;
border: 1px solid red;
}
#box01{
background-color: blue;
position: relative;
/* top left right bottom */
/* left:500px; *//* 距离左边框向右移动500个像素点 */
right:100px;/* 向左移动 */
}
#box02{
background-color: green;
position: relative;
/* 往上移动到顶部 */
bottom:200px;
}
#box03{
background-color: pink;
position: relative;
/* 往上移动到顶部 */
top:-400px;
}
</style>
</head>
<body>
<div id="box01">
</div>
<div id="box02"></div>
<div id="box03"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>相对定位操作2</title>
<style type="text/css">
*{
box-sizing: border-box;
}
div{
height: 300px;
width: 300px;
border: 1px solid red;
}
#father{
background-color: blue;
}
#son{
height: 100px;
width: 100px;
border: 1px solid red;
background-color: purple;
position: relative;
/* 向右向下使用left和top */
left:100px;
top:100px;
}
#brother{
background-color: pink;
position: relative;
left: 300px;
bottom: 300px;
}
</style>
</head>
<body>
<div id="father">
<div id="son"></div>
</div>
<div id="brother"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>绝对定位操作1</title>
<style type="text/css">
*{
box-sizing: border-box;
}
div{
height: 300px;
width: 300px;
border: 1px solid red;
}
#box01{
background-color: blue;
position: absolute;
left:500px;
}
#box02{
background-color: yellow;
}
#box03{
background-color: black;
}
</style>
</head>
<body>
<div id="box01"></div>
<div id="box02"></div>
<div id="box03"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>绝对定位操作2</title>
<style type="text/css">
*{
box-sizing: border-box;
}
div{
height: 300px;
width: 300px;
border: 1px solid red;
}
#father{
background-color: green;
/* position: absolute; */
/* position: relative; */
/* position: static; */
/* left: 500px; */
margin-left: 500px;
}
#son{
height:100px;
width:100px;
background-color: blue;
/* position: absolute; */
/* left: 400px; */
}
#grandson{
height: 50px;
width: 50px;
background-color: purple;
position: absolute;
left: 25px;
top:25px;
}
#uncle{
background-color: yellow;
position: absolute;
}
</style>
</head>
<body>
<div id="father">
<div id="son">
<div id="grandson"></div>
</div>
</div>
<div id="uncle"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>固定定位操作</title>
<style type="text/css">
*{
box-sizing: border-box;
padding: 0;
margin: 0;
}
div {
height: 300px;
border: 1px solid red;
}
#div01{
background-color: black;
}
#div02{
height: 500px;
background-color: purple;
}
#div03{
background-color: yellow;
position: fixed;
top:200px;
width: 100%;
}
</style>
</head>
<body>
<div id ="div03">我是固定定位</div>
<div id="div01">我是相对定位</div>
<div id="div02">我是绝对定位</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Z-index的使用</title>
<style type="text/css">
*{
box-sizing: border-box;
padding: 0;
margin: 0;
}
div {
height: 200px;
width: 200px;
border: 1px solid red;
}
.div01{
background-color: green;
position: absolute;/* 定位流 */
z-index: 101;
}
.div02{
background-color: purple;
position: fixed;/* 定位流*/
/* left:600px; */
z-index: 1;
}
.div03{
background-color: pink;
position: relative; /* 定位流 */
/* left: 200px; */
z-index: 10;
}
.div04{
background-color: cyan;
}
</style>
</head>
<body>
<div class="div01"> </div>
<div class="div02"> </div>
<div class="div03"> </div>
<div class="div04"> </div>
</body>
</html>
// 给div添加背景色为红色
document.getElementById("one").style.height = "100px";
document.getElementById("one").style.width = "100px";
document.getElementById("one").style.border = "1px solid red";
document.getElementById("one").style.backgroundColor = "red";
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>js代码引入方式</title>
<script type="text/javascript">
prompt("需要给我输入一个文字信息");
</script>
</head>
<body>
<!-- 通过内联式,植入到html文件中 -->
<script type="text/javascript">
/* 就是js代码 多行注释*/
// 单行注释
alert("点我!!!");
</script>
<div>
我是第一个div标签
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Js外联式引入</title>
<!-- 引入外部的js文件 -->
<!-- <script type="text/javascript" src="./one.js"></script> -->
<script type="text/javascript">
window.onload = function reload() {
document.getElementById("one").style.border = "1px solid red";
document.getElementById("one").style.height = "300px";
document.getElementById("one").style.width = "800px";
document.getElementById("one").style.backgroundColor = "green";
}
</script>
</head>
<body>
<div id="one">我是一个div标签</div>
<!-- <script type="text/javascript" src="./one.js"></script> -->
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Js外联式引入</title>
<!-- 引入外部的js文件 -->
<!-- <script type="text/javascript" src="./one.js"></script> -->
<script type="text/javascript">
window.onload = function reload() {
document.getElementById("one").style.border = "1px solid red";
document.getElementById("one").style.height = "300px";
document.getElementById("one").style.width = "800px";
document.getElementById("one").style.backgroundColor = "green";
}
</script>
</head>
<body>
<div id="one">我是一个div标签</div>
<!-- <script type="text/javascript" src="./one.js"></script> -->
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
body{
/* overflow: hidden; */
overflow-x: hidden;
}
div{
height: 100px;
width:2000px;
}
</style>
</head>
<body>
<a href="http://www.baidu.com" target="box">百度一下</a><br>
<iframe name="box" height="500px" width="100%" src="http://www.baidu.com" scrolling = "no">
</iframe>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</body>
</html>