4、css之position
一、position
position属性:指定一个元素(静态的,相对的,绝对或固定)的定位方法的类型。
1、fixed值
fixed值:生成固定定位的元素,相对于浏览器窗口进行定位。元素的位置通过 "left", "top", "right" 以及 "bottom" 属性进行规定。 ############################
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div onclick="GoTop();" style="height: 50px; width: 50px; background-color: black; color: white;
position: fixed;
bottom:20px;
right: 20px;
">返回顶部</div> <div style="height: 5000px; background-color: #dddddd"></div> <script>
function GoTop() {
document.body.scrollTop = 0;
}
</script>
</body>
</html> ###############################
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.pg-header{
height: 48px;
background-color: black;
color: #dddddd;
position: fixed;
top: 0px;
right: 0;
left: 0px;
} .pg-body{
background-color: #dddddd;
height: 5000px;
margin-top: 50px;
}
</style>
</head>
<body>
<div class="pg-header">头部</div>
<div class="pg-body">内容</div>
</body>
</html>
2、absolute、relative组合使用
absolute:
生成绝对定位的元素,相对于 static 定位以外的第一个父元素进行定位。
元素的位置通过 "left", "top", "right" 以及 "bottom" 属性进行规定。 relative:
生成相对定位的元素,相对于其正常位置进行定位。
因此,"left:20" 会向元素的 LEFT 位置添加 20 像素。 #############################
##relative在父标签中,absolute在子标签中;
##absolute是相对于父标签来定位的;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div style="position:relative; width: 500px; height: 200px; border: 1px solid red; margin: 0 auto;">
<div style="position: absolute; left: 0; bottom: 0; width: 50px; height: 50px; background-color: black;"></div>
</div>
</body>
</html>
3、层级显示
##代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div style="z-index: 2; position: fixed; top: 50%; left: 50%;
margin-left: -250px; margin-top: -200px; background-color: white; height: 400px; width: 500px;">
<input type="text">
</div> <div style="z-index: 1; position: fixed; background-color: black;
top: 0;
bottom: 0;
right: 0;
left: 0;
opacity: 0.4;"></div> <div style="height: 5000px; background-color: green;">最底层页面</div>
</body>
</html> ##
opacity: 0.4; //透明度
z-index: 1; //层级顺序,值小的层在下面
4、css之position的更多相关文章
- 深入理解css中position属性及z-index属性
深入理解css中position属性及z-index属性 在网页设计中,position属性的使用是非常重要的.有时如果不能认识清楚这个属性,将会给我们带来很多意想不到的困难. position属性共 ...
- div+css定位position详解
div+css定位position详解 1.div+css中的定位position 最主要的两个属性:属性 absolute(绝对定位) relative(相对定位),有他们才造就了div+css布局 ...
- 十步图解CSS的position
CSS的positon,我想做为一个Web制作者来说都有碰到过,但至于对其是否真正的了解呢?那我就不也说了,至少我自己并不非常的了解其内核的运行.今天在Learn CSS Positioning in ...
- css 之position用法详解
css 之position用法详解: http://www.jb51.net/web/77495.html
- CSS中Position属性
也许你看到这个标题觉得很简单,确实这是一篇关于CSS中Position属性基础知识的文章,但是关于Position的一些细节也许你不了解. 1.简介 position有五个属性: static | r ...
- CSS的position(位置)
position: 位置,absolute绝对位置,相对于浏览器边界的位置:relative相对位置,相对于它本应该出现的位置.fixed:固定位置,它不会随着滚动. 设置好position之后,就可 ...
- CSS的position设置
CSS的position设置: <%@ page language="java" contentType="text/html; charset=UTF-8&quo ...
- 关于CSS 的position定位问题
对于初学者来说,css的position定位问题是比较常见的.之前搞不清楚postion定位是怎么回事,排版一直歪歪斜斜的,老是排不好 css的定位一般来说,分为四种: position:static ...
- 《css定位 position》课程笔记
这是我学习课程css定位 position时做的笔记! 本节内容 html的三种布局方式 position可选参数 z-index 盒子模型和定位的区别 侧边栏导航跟随实例 html的三种布局方式 三 ...
- css的position中absolute和fixed的区别
fixed:固定定位 absolute:绝对定位 区别很简单: 1.没有滚动条的情况下没有差异 2.在有滚动条的情况下,fixed定位不会随滚动条移动而移动,而absolute则会随滚动条移动 常用场 ...
随机推荐
- A20 Gate信号
https://doc.docsou.com/ba8e6b0612d6a989b7cebeaae-5.html Gate A20 Option 功能:设置A20 地址线的控制模式 设定值:Fast 或 ...
- EOF需要两次才能结束输入
.EOF作为文件结束符时的情况: EOF虽然是文件结束符,但并不是在任何情况下输入Ctrl+D(Windows下Ctrl+Z)都能够实现文件结束的功能,只有在下列的条件下,才作为文件结束符.(1)遇 ...
- Redis 3.2.4编译安装
1. 下载安装包 wget url tar zxvf redis-3.2.4.tar.gz 2. 编译安装 cd redis-3.2.4/src/ sudo make && make ...
- 模式识别之分类器knn---c语言实现带训练数据---反余弦匹配
邻近算法 KNN算法的决策过程 k-Nearest Neighbor algorithm是K最邻近结点算法(k-Nearest Neighbor algorithm)的缩写形式,是电子信息分类器算 ...
- NoSQL的四大类型
1 键值数据库 相关产品:Redis.Riak.SimpleDB.Chordless.Scalaris.Memcached 应用:内容缓存 优点:扩展性好.灵活性好.大量写操作时性能高 缺点:无法存储 ...
- mysql的事务隔离级别及其使用场景
1 什么是事务隔离级别 事务隔离指的是事务之间同步关系. 2 食物隔离级别的分类 第一隔离级别,脏读级别 在脏读级别下,第一个事务修改了某个数据,但是还没有提交,第二个事务可以读取到这个未提及的数据. ...
- sticky session 粘性会话
New Elastic Load Balancing Feature: Sticky Sessions | AWS News Blog https://amazonaws-china.com/cn/b ...
- Eclipse中同时打开多个Console
实现方法: 1.点击Open Console案例下拉三角,选择New Console View. 2.点击Pin Console按钮將两个控制台同时固定住. 3.点击Display Selected ...
- 什么是aop?-------转
什么是AOP? http://www.cnblogs.com/zhugenqiang/archive/2008/07/27/1252761.html#commentform(转) AOP(Aspec ...
- Android Button Maker(在线生成android shape xml文件的工具),真方便!
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/scry5566/article/details/25379275 直接上地址:http ...