HTML/CSS新手入门学习——定位1

定位position

1.将元素移动摆到想要的位置上去

2.可选值:

1.static:默认值,不打开定位

2.relative:相对定位

3.absolute:绝对定位

4.fixed:固定定位


相对定位relative

position:relative;

left: ;right: ;

top: ;bottom: ;


相对定位是相对于原来的位置移动,!给出的值不是移动方向

相对定位开启后没有脱离文档流

相对定位会让元素上升一个层级,移动的元素会盖住原来的元素


<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

    <style type="text/css">

    .box1{

        width: 200px;

        height: 200px;

        background-color: blueviolet; 

    }

    .box2{

        width: 200px;

        height: 200px;

        background-color:blue;

        position: relative;

        left: 100px;

        bottom: 100px;

        opacity: 0.5;/*可以设置透明度*/

    }

    .box3{

        width: 200px;

        height: 200px;

        background-color: blanchedalmond;

        position: relative;

        left: 200px;

        bottom: 200px;

        opacity: 0.5;

    }

    </style>

</head>

<body>

    <div class="box1"></div>

    <div class="box2"></div>

    <div class="box3"></div>

</body>

</html>

效果:


©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。