定位

Position

普通流 定位
Position:static 默认行为
从上到下从左到右按顺序以流的方式进行定位
子元素会排列在父容器element内
Inline-block



##相对定位(也叫已定位元素)
Position:relative
在普通流的基础上进行偏移
普通流的位置仍然保留
```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div{
           width: 200px;
            height: 200px;
            background-color: orange;
            margin: 2px;
        }
        #a{
            background-color: rebeccapurple;
            position: relative;
            left: 170px;
            top: 20px;
        }
        #b{
           position: relative;
            top: -30px;
        }
        #c{
            width: 100px;
            height: 100px;
            background: orangered;
            position: relative;
            left: 200px;
        }
        #d{
            background: paleturquoise;
            position: relative;
            right: 0px;
            top: 0px;
            width: 100px;
            height: 100px;
        }
    </style>
</head>
<body>
<div id="a">ee
<div id="c">tt</div>
<div id="d">rr</div>
</div>
<div id="b">tt</div>
</body>
</html>

##绝对定位
Position:absolut
在普通流中完全消失
Left top 以左上角为原点进行调整
Right bottom 以右下角为原点调整
当是绝对的时候会从正常流失
Right=0px top=0px 右上角定位
Left=0px bottom=opx 左下角定位
```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        #a{
            position: relative;
            width: 300px;
            height: 300px;
            background-color: orange;
            left: 20px;
            top: 20px;
        }
        #b{
            z-index: 2;
            position: absolute;
            /*top: 10px;*/
            /*left: 10px;*/
            bottom: 0px;
            left: 0px;
            width: 100px;
            height: 100px;
            background-color: orangered;
        }
        #c{
            /*调整图层高度*/
            z-index: 4;
            position: absolute;
            right: 0px;
            top: 0px;
            width: 50px;
            height: 50px;
            background-color: paleturquoise;
        }
        #t{
            top: 50px;
            right: 0px;
            position: fixed;
           background-color: red;
            width: 100px;
            height: 100px;
        }
    </style>
</head>
<body>
<div id="a">
    <div id="b"></div>
    <div id="c"></div>
</div>
<div id="t">sd</div>
    </body>
</html>

固定式布局
Position:fixed;
一窗口为标准

浮动(改进的普通流)
Float:left/right
普通流会认为浮动不存在


©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 14,261评论 1 92
  • 浮动元素有什么特征?对父容器、其他浮动元素、普通元素、文字分别有什么影响? 特征: 1、浮动元素会脱离正常的文档流...
    我要认真学前端阅读 2,891评论 0 5
  • 自我总结: 浮动是实现布局的一种常见方式 浮动脱离普通文档流,即页面渲染时,盒模型按标准会将父元素所设置的属性将页...
    饥人谷_远方阅读 496评论 0 0
  • 浮动元素有什么特征?对父容器、其他浮动元素、普通元素、文字分别有什么影响?浮动的元素会脱离文档流,向左或者向右移动...
    饥人谷_wanpp阅读 817评论 0 49
  • 一、浮动元素有什么特征?对父容器、其他浮动元素、普通元素、文字分别有什么影响? 特征:1、浮动模型是一种可视化格式...
    青鸣阅读 1,351评论 0 0

友情链接更多精彩内容