css position relative absolute fixed
- relative相对定位
将定位元素偏离正常文档流,但占用正常文档流的位置。如下图中:
1.relative相对定位是相对于自身的定位,relative元素不加position定位,位置是在虚框位置。
relative元素加了position: relative;将根据top/bottom/left/right,基于虚框的margin左上外角定位的。
2.虚框为relative元素占用的正常文档流的位置,所以正常元素到下面了。
<style>* {padding: 0;margin: 0;}#sub1 {height: 100px;width: 100px;position: relative;top: 100px;left: 100px;background-color: red;}#sub2 {height: 100px;width: 100px; background-color: green;}</style><body style="border:1px black solid"><div id="sub1">relative元素</div><div id="sub2">正常元素</div> </body>
- absolute绝对定位
将定位元素偏离正常文档流,不占用正常文档流的位置。如下图中:
<style>* {padding: 0;margin: 0;}#sub1 {height: 100px;width: 100px;position: absolute;/* margin: 10px;border: 10px;padding: 10px; */top: 100px;left: 100px;background-color: red;}#sub2 {height: 100px;width: 100px;/* position: relative;top: 100px;left: 100px; */background-color: green;}</style> <body style="border:1px black solid"><div id="sub1">absolute元素</div><div id="sub2">正常元素</div> </body>
1.absolute元素的父元素没有position定位,absolute元素相对于body定位
<style>* {padding: 0;margin: 0;}#parent {height: 100px;width: 100px;background-color: yellow;/* position: absolute; */margin: 100px;padding: 100px;}#child {height: 100px;width: 100px;position: absolute;/* margin: 10px;border: 10px;padding: 10px; */top: 100px;left: 100px;background-color: red;}</style> <body style="border:1px black solid"><div id="parent">父元素<div id="child">absolute元素</div></div> </body>
2.absolute元素的父元素有position定位(absolute或relative),absolute元素相对于父元素的padding左上外角进行定位
<style>* {padding: 0;margin: 0;}#parent {height: 100px;width: 100px;background-color: yellow;position: absolute;margin: 100px;padding: 100px;}#child {height: 100px;width: 100px;position: absolute;/*或者positi:relative*//* margin: 10px;border: 10px;padding: 10px; */top: 100px;left: 100px;background-color: red;}</style> <body style="border:1px black solid"><div id="parent">父元素<div id="child">absolute元素</div></div> </body>
- fixed固定定位
脱离文档流,不占用正常文档流,相对于body定位
转载于:https://www.cnblogs.com/chrisghb8812/p/9909668.html
css position relative absolute fixed相关推荐
- html中的绝对定位怎么写,CSS position绝对定位absolute relative
DIV CSS position绝对定位absolute relative教程篇 常常使用position用于层的绝对定位,比如我们让一个层位于一个层内具体什么位置,为即可使用position:abs ...
- html本文框百分比定位,HTML中三种定位relative,absolute,fixed后,盒子的百分比宽度及位置易错点...
1 . 相对定位relative:顾名思义,相对定位是相对于自己的位置来进行偏移,如下图: 以盒子中心为基准,为每条边的正方向,例: 向右移动20px : 代码为left:20px;或者right:- ...
- CSS中position属性(relative,absolute,fixed)和display中的inline-block
前言 平时很少写CSS,用的多也就是Bootstrap来堆样式,写起来快一点,但是有时候需要自己写,很久没写容易忘记,这里记录下这两个常用属性position和display 这里贴一条CSDN设置图 ...
- CSS定位总结:position=static/relative/absolute/fixed时的区别、top/bottom/left/right与margin外边距的运用
准备布局: <!DOCTYPE html> <html> <head> <style> *{ margin:0; padding:0; } .base- ...
- CSS position属性absolute relative等五个值的解释
目前几乎所有主流的浏览器都支持position属性("inherit"除外,"inherit"不支持所有包括IE8和之前版本IE浏览器,IE9.IE10还没测试 ...
- CSS position绝对定位absolute relative
常常使用position用于层的绝对定位,比如我们让一个层位于一个层内具体什么位置,为即可使用position:absolute和position:relative实现. 一.position语法与结 ...
- CSS:position:relative;的认识
CSS定位的原理 把浏览器窗口想象成一个坐标系统: CSS定位的原理是:你可以将任何盒子(box)放置在坐标系统的任何位置上. 采用CSS定位技术来放置元素是非常精确的.相对于使用表格.透明图像或其他 ...
- HTML中三种定位relative,absolute,fixed后,盒子的百分比宽度及位置易错点
1 . 相对定位relative:顾名思义,相对定位是相对于自己的位置来进行偏移,如下图: 以盒子中心为基准,为每条边的正方向,例: 向右移动20px : 代码为left:20px;或者right:- ...
- html绝对定位向下,HTML中三种定位relative,absolute,fixed使用后出现的一些问题
1 . 相对定位relative:顾名思义,相对定位是相对于自己的位置来进行偏移,如下图: 以盒子中心为基准,为每条边的正方向,例: 向右移动20px : 代码为left:20px;或者right:- ...
- CSS的定位 position属性的 absolute relative static fixed的区别及用法
CSS中position一般是跟盒子结合做出效果的,浮动可以实现盒子在横向上的排列,但是如何实现在盒子上重叠另一个盒子的效果呢?就需要CSS的position来实现 position属性有四个,分别有 ...
最新文章
- VS2005 常用快捷键
- 吐血整理:手拿几个大厂 Offer 的秘密武器!
- JAVA调用R语言之Rserve
- cf-Global Round2-C. Ramesses and Corner Inversion(思维)
- 不可不知的:iOS开发的22个诡异技巧
- ML.NET 推荐引擎中一类矩阵因子分解的缺陷
- Visual Studio 2017 15.8 正式发布,测试速度提高 82%
- Job for slapd.service failed because the control process exited with error code. See systemctl stat
- 跨平台的PHP+MySQL_跨平台的PHP+MySQL
- java outputstrea_java的InputStream和OutputStream的理解【转】
- windows下安装wget
- maxscale mysql_安装maxscale MySql读写分离
- 怎么看电脑支持多少兆网速_电脑网速怎么看(电脑怎么看网速多少兆)
- c语言快捷键的使用方法,电脑快捷键的使用方法
- 陶哲轩(Terence Tao)对从事数学职业的建议
- 苹果电脑python制作圣诞树的教程
- 双目立体匹配修炼之路
- PCI-PCIE中断机制之一
- USB TYPE -A -B -C 接口
- mysql inner join 链接三个或多个表
热门文章
- Spring读书笔记(一)
- webStrom 开始你的第一个React应用
- (已拿offer)2017腾讯暑期实习生从笔试到面试总结(附带华为、阿里面试经历)...
- many to many mysql_mysql “Too many connections” 解决办法
- python代码怎么运行_如何让Python代码加速运行?
- python变量存为matlab,将matlab变量导出为python用法的文本
- java案例代码2-素数判断测试
- 帆软FineMobile 自适应
- esxi 需要整合 空间不足_太炫酷了!10月微信新花样!微信情侣空间怎么设置如何弄微信情侣空间在哪里开...
- html单元格选中状态,UITableViewCell 设置单元格选中后只显示一个打勾的状态