JAVASCRIPT

[JavaScript]position : sticky 응용하기

[JavaScript]position : sticky 응용하기

<!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>

        *{
            margin:0;
            padding: 0;
        }
        
        .black {
            background: black;
            height: 1000px;
            margin-top: 500px;
        }

        .text {
            float: left;
            width: 300px;
            color: #fff;
        }

        .image {
            float: right;
            width: 250px;
            position: sticky;
            top: 300px; /* 위에서부터 몇 픽섹 고정시킬지 지정 */
        }

        img {
            width: 100%;
        }

    </style>
</head>

<body>
    <div class="black">
        <div class="image">
            <img src="img/iphone1.png" width="50%">
        </div>

        <div style="clear : both"></div>
        <div class="text">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has
            been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type
            and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap
            into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the
            release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
            software like Aldus PageMaker including versions of Lorem Ipsum.</div>
        </div>

    <div style="margin-bottom: 800px;"></div>

</body>

</html>
position : sticky를 사용하여 div를 화면에 고정시킬 수 있습니다.

 

최신글