模型定位
来源:互联网 发布:cpu百分率 linux命令 编辑:程序博客网 时间:2024/06/05 19:22
一.position属性
- 对当前标签对象进行定位操作,属性规定元素的定位类型
- 取值范围: 静态(static),相对(relative),绝对(absolute)、固定(fixed)
- css四个属性(top、left、right、bottom)只有在设置了position值为relative、absolute、fixed情况下才有效
二.relative(相对定位)
- 格式说明:position:relative
- 相对定位特点:
①. 通过top、left、bottom、right来设置元素的新位置偏移(相对于当前位置)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head> <title>Title</title> <style type="text/css"> .box1,.box2{ width: 100px; height: 100px; position: relative; } .box1{ background-color: red; top: 10px; z-index: 1; } .box2{ margin-left: 10px; background-color: #0000FF; } </style></head><body> <div class="box1"></div> <div class="box2"></div></body></html>
三.fix(固定定位)
- 格式说明:position:fixed
- 固定定位特点:
- 通过top、left、bottom、right来设置元素的新位置偏移(相对于浏览器视窗)
- 固对定位的元素脱离标准文档流,不受文档流约束
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title> <style type="text/css"> *{ margin: 0; padding: 0; } .bg1{ background-color: red; } .bg2{ background-color: #6c5d4c; } .bg3{ background-color: yellow; } .bg{ height: 500px; position: relative; } .fixBox{ position: fixed; z-index: 1; top: 10px; left: 20px; width: 100px; height: 400px; background-color: lightgray; } </style></head><body> <div class="fixBox">固定的面板</div> <div class="bg bg1"> </div> <div class="bg bg2"> </div> <div class="bg bg3"> </div></body></html>
四.absolute(绝对定位)
- 格式说明:
position:absolute
; - 绝对定位特点
- 通过top、left、bottom、right来设置元素的新位置偏移
- 相对定位的元素脱离标准文档流
案例:
- 未使用绝对定位两个div布局如下
- 当红色div使用绝对定位后,蓝色占据原来红色div的位置( 因为相对定位的元素脱离标准文档流)代码如下
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title> <style> .box1,.box2{ width: 100px; height: 100px; } .box1{ position: absolute; top: 50px; left: 50px; background-color: red; } .box2{ background-color: #0000FF; } </style></head><body> <div class="box1"></div> <div class="box2"></div></body></html>
五.定位参考点
- 如果绝对定位盒子外层没有盒子
- top:以距离页面顶部具体top长度显示
- bottom:以距离当前浏览器底部bottom值显示
- 如果绝对定位盒子外层还有盒子
- 默认相对于浏览器绝对定位偏移
- 如果要相对父容器绝对定位,则要遵循如下规则:父元素必须要有定位(绝、相、固)设置
六.z-index定义
- 属性设置元素的堆叠顺序。拥有更高堆叠顺序的元素总是会处于堆叠顺- 序较低的元素的前面(默认为0)
- z-index只有在当前元素设置了position的时候才有效
- 特性:
- 随父性:父元素的z-index值,会影响子元素的重叠效果
0 0
- 模型定位
- 盒子模型&position定位
- 盒模型定位
- 层模型:CSS定位
- 盒子模型与定位
- 层模型--固定定位
- 层模型--固定定位
- 盒子模型, 定位
- 浮动清除,模型定位
- 盒子模型的定位
- css盒状模型定位
- CSS:盒子模型与定位
- CSS 框模型和定位
- 【Html】层模型--绝对定位
- 【Html】层模型--相对定位
- 【Html】层模型--固定定位
- CSS盒子模型的定位
- 盒子模型、CSS的定位
- 算法:请找出数组中的某个数,它的左侧数字相加之和等于右边。
- 布隆过滤器(Bloom Filter)的原理和实现
- 六.javaweb之Servlet详细原理介绍
- jQuery控制页面样式的变化
- 49. Group Anagrams
- 模型定位
- seajs的使用
- kaggle入门篇一【手写数字识别】
- python之FTP程序(支持多用户在线)
- Qt-QML-给我的导航条写一个动画-State-Transition
- 斯坦福演讲:别在不断的优秀里,最终走向平庸
- RxJava—创建操作符
- 编程语言 标记语言 脚本语言分别有哪些? 区别是什么?
- 短进程优先的调度算法详解