zoaseo
To Infinity And Beyond
zoaseo
전체 방문자
오늘
어제
  • 분류 전체보기 (763)
    • 개발이 좋아서 (381)
      • SAP가 좋아서 (3)
      • Java가 좋아서 (42)
      • Spring이 좋아서 (50)
      • JPA가 좋아서 (0)
      • QueryDSL이 좋아서 (26)
      • Docker가 좋아서 (7)
      • Redis가 좋아서 (7)
      • AWS가 좋아서 (5)
      • CI/CD가 좋아서 (6)
      • Troubleshooting이 좋아서 (4)
      • Kotlin이 좋아서 (7)
      • SQL이 좋아서 (6)
      • HTTP가 좋아서 (21)
      • JavaScript가 좋아서 (30)
      • TypeScript가 좋아서 (6)
      • Vue가 좋아서 (21)
      • Flutter가 좋아서 (61)
      • React가 좋아서 (20)
      • Redux(React)가 좋아서 (2)
      • Angular가 좋아서 (22)
      • HTML이 좋아서 (9)
      • CSS가 좋아서 (15)
      • PHP가 좋아서 (9)
      • Illustrator가 좋아서 (2)
    • 노력이 좋아서 (169)
    • 결과물이 좋아서 (14)
    • 코딩연습이 좋아서 (168)
      • 이론이 좋아서 (62)
      • SQL이 좋아서 (90)
    • 유용한 사이트가 좋아서 (28)
    • Github (2)

인기 글

티스토리

hELLO · Designed By 정상우.
zoaseo

To Infinity And Beyond

<step17>'css_position'
노력이 좋아서

<step17>'css_position'

2022. 4. 12. 11:56

1) position.html

<!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; box-sizing: border-box;}
        body {
            height: 3000px;
        }
        div {
            width: 200px;
            height: 200px;
            background-color: tomato;
            border: 3px solid #333;
        }
        div:nth-child(2) {
            position: fixed;
            top: 0;
            right: 0;
        }
    </style>
</head>
<body>
    <div>box1</div>
    <div>box2</div>
    <div>box3</div>
    <div>box4</div>
</body>
</html>

2) position_02.html

<!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; box-sizing: border-box;}
        #parent { 
            width: 1000px;
            background: lightblue;
            margin: 0 auto;
            height: 500px;
            position: relative;  /* 기준이 된다! */
        }
        #children {
            width: 100%;
            height: 200px;
            background: aquamarine;
            position: absolute;  /* 원래는 브라우저 크기만큼이지만 다른 요소들의 속성이 relative이면 그것을 기준으로 한다! */
            top: 0;
            left: 0;
        }
        ul {
            width: 1000px;
            margin: 0 auto;
            padding: 40px;
        }
        li {
            float: left;
            width: 25%;
            text-align: center;
            list-style: none;
            background-color: aqua;
            line-height: 60px;
            position: relative;
        }
        a { text-decoration: none; color: inherit;}
        li::after {
            content: "";
            display: block;
            width: 3px;
            height: 40px;
            background-color: tomato;
            position: absolute;
            right: 0px;
            top: 10px;
        }
    </style>
</head>
<body>
    <div id="parent">
        부모div
        <div id="children">자식div</div>
    </div>
    <ul>
        <li><a href="#">menu1</a></li>
        <li><a href="#">menu2</a></li>
        <li><a href="#">menu3</a></li>
        <li><a href="#">menu4</a></li>
    </ul>
</body>
</html>

3) position_03.html

<!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; box-sizing: border-box;}
        #parent {
            width: 1000px;
            height: 400px;
            background-color: lightblue;
            position: relative;
        }
        .children {
            width: 100px;
            height: 100px;
            background-color: tomato;
            border: 3px solid #333;
        }
        .children:nth-child(1) {
            z-index: 10;
            position: relative;
        }
        .children:nth-child(2) {
            position: absolute;
            top: 50px;
            z-index: 5;
        }
    </style>
</head>
<body>
    <div id="parent">
        <div class="children">자식div</div>
        <div class="children">자식div</div>
    </div>
</body>
</html>

4) position_sticky.html

<!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; box-sizing: border-box;}
        #parent1 {
            width: 1200px;
            margin: 0 auto;
            height: 1300px;
            background-color: yellow;
            position: relative;
        }
        #parent2 {
            width: 1200px;
            margin: 0 auto;
            height: 1300px;
            background-color: blue;
        }
        #children {
            width: 200px;
            height: 200px;
            position: sticky; /* fixed와 다르게 부모요소 안에서만 고정이 됨 */
            left: 200px;
            top: 200px;
            background-color: tomato;
        }
    </style>
</head>
<body>
    <div id="parent1">
        첫번째 div
        <div id="children">자식div</div>
    </div>
    <div id="parent2">
        두번째 div
    </div>
</body>
</html>

'노력이 좋아서' 카테고리의 다른 글

<step19>'css_flex'  (0) 2022.04.14
<step18>'css_hover,position_실습'  (0) 2022.04.13
<step17>'css_hover'  (0) 2022.04.12
<step17>'css_실습'  (0) 2022.04.11
<step16>'css_float, before, after'  (0) 2022.04.11

    티스토리툴바