html修改层的相对位置,css-相对定位-绝对定位-锁定-上下层-列表浮动

css三种定位方式:普通定位如:框与框之间普通排列,浮动定位和绝对定位

1.普通定位中的框排列display属性。实现块元素与行内元素互相转换如:

默认:

h1{background-color:orange;}

span{background-color:red;}

默认h1

默认h1

span|行内标签默认|span

span|行内标签默认|span

1d56eabbf87b98512d2b65d6fa891221.png

display属性后:

h1{background-color:orange;display:inline;/*改为行内*/}

span{background-color:red;display:block;/*改为块*/}

默认h1

默认h1

span|行内标签默认|span

span|行内标签默认|span

136a527774eb97de04203dbeea1d3fd4.png

还有:display:none属性表示隐藏,让某一个框隐藏。display:block;以块的形式展示

display:inline;以行的形式展示

2.相对定位:position:relative;

默认如下:

#father{

width:900px;

height: 600px;

background-color: antiquewhite;

}

#a{

width:300px;

height: 200px;

background-color: red;

display:inline-block;

}

#b{

width:300px;

height: 200px;

background-color: blue;

display:inline-block;

}

#c{

width:200px;

height: 200px;

background-color: yellow;

display:inline-block;

}

aaa
bbb
ccc

d92edd86a336409afff1f7ba41177ca2.png

b相对于之前的位置向下想右移动50如下:

fd9b5270a433d32e9d2c13a86093a011.png

代码:修改b的样式

#b{

width:300px;

height: 200px;

background-color: blue;

display:inline-block;

position:relative;/*相对于现在的位置进行配置*/

top:50px;

left:50px;

}

3.绝对定位相对于father标签进行配置【position:absolute;】

#b{

width:300px;

height: 200px;

background-color: blue;

display:inline-block;

position:absolute;/*绝对定位根据father进行的定位进行配置*/

top:50px;

left:50px;

}

364f3733388bfb8ad104f7e39df065e7.png

4.窗口锁定  position:fixed

无论滑框怎么滑动,按钮始终不动,类似于excel固定菜单一样。position:fixed;

back to top

span{

position:fixed;

/*相对于页面窗口固定不变,类似于右边京东天猫工具栏*/

background-color:green;

right:20px;

bottom:20px;

}

8bfb8b57bc7937197430b0d8da9df10c.png

5.设置窗口上下滑动按钮;overflow:auto;

p{margin-top:100px;

width:350px;

height:100px;

overflow:auto;

啦啦啦啦啦啦啦奥罗拉啊拉拉拉拉案例啊啦啊啦啦啦啦拉拉阿拉蕾阿拉拉拉拉案例啊啊啦啊啦啊阿拉拉啊啊啦啊阿拉阿拉拉阿拉拉拉拉案例啊啊啦啊啦啊阿拉阿拉拉拉拉案例啊啊啦啊啦啊阿拉阿拉拉拉拉案例啊啊啦啊啦啊阿拉阿拉拉拉拉案例啊啊啦啊啦啊阿拉

2bd360c3dff48b976e41a51b1fea5f4c.png

6.将窗口至于底层或顶层

279b23066cf51e47244b74ad770add39.png

至于底层

dba84cfa17223ac53ab60e4a39a570b2.png

#b{

width:800px;

height: 200px;

background-color: blue;

display:inline-block;

position:absolute;

top:50px;

left:50px;

z-index:-1;

/*z-index:1;设置将此标签至于底层或顶层*/

}

034b5cebb194ce7c62c5b836287f4b9d.png

8.主要定义所用标签

a8f05021d505868a658e58cabdd3724e.png

9.css浮动

浮动就是让元素跳出正常的布局流,浮动在上层的一个框内,可向右或向左,至到碰到外层框才会改变浮动方向

定义浮动用:float:left向左 right向右 none不浮动 inherit 继承父元素float属性值。利用无须列表+浮动制作导航栏

---------------------

html02

ul{float:left;

width:100%;

padding:0;

margin:0;

list-style-type:none;/*设置列表样式图标为wu*/

}

a{float:left;

width:7em;

text-decoration:none;/*连接去掉下划线*/

color:white;

background-color:purple;

padding:0.2em 0.6em;

border-right:1px solid white;}

a:hover{background-color:#ff3300;}

li{display:inline;}

--------------------

333354b42eb0e158a950c8c3df977204.png

3bf20ded2dda2b598d417159af00ff16.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值