Position Absolute, Relative, Fixed and Sticky in CSS

 <!DOCTYPE html>

<html lang="en">


<head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

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

    <title>Document</title>

    <style>

        .container {

            border: 2px solid black;

            background-color: rgb(5, 5, 5);

            height: 3444px;

        }


        /* CSS Position: static(default), absolute, relative, fixed, sticky */

        .box {

            display: inline-block;

            border: 2px solid red;

            width: 150px;

            height: 150px;

            margin: 2px;

        }


        #box3 {

            /* relative: relative to its normal position */

            /* position: relative; */

            /* absolute: absolute to the position of its first parent position */

            /* position: absolute; */

            /* top: 34px;

            left: 34px; */

            /* fixed: position the element relative to the browser window */

            /* position: fixed;

             right: 4px;

             bottom: 2px; */


            position: sticky;

            top: 3px;



        }

    </style>

</head>


<body>

    <div class="container">

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

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

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

        <div class="box" id="box4"></div>

    </div>


</html>

</body>

Comments

Popular posts from this blog

Transform Property In CSS

More on CSS Selectors