CSS POSITION

2020/CSS 2020. 2. 16. 16:51
반응형

CSS에서 사용되는 4가지 포지션에 대해 말해 볼까 합니다.

Position 에는 static, pixed, absolute, relative가 있습니다.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Position</title>
  <style>
    body,html{
      height: 100%;
      margin:0;
      padding:0;
    }
    body{
      height: 400%;
      background-color: red;
    }
    /* Position Fixed
    #boxOne{
      height:300px;
      width:300px;
      background-color: yellow;
      position:static;
    }
    #boxTwo{
      height:300px;
      width:100%;
      background-color: green;
      position:fixed;
      bottom:30%;
      left:0;
    }*/
    /* Absolute */
    .abs-box{
      width:400px;
      height: 400px;
      background-color: yellow;
      position: relative; /* Remember to put relative here or the child will go to the body*/
    }
    .abs-child{
      width:100px;
      height: 100px;
      background-color: green;
      position: absolute;
      right:10px;
      top:10px;
    }
  </style>
</head>
<body>
  <div class="abs-box">
    <div class="abs-child"></div>
  </div>
  <!-- Position Fixed
  <div id="boxOne">
    <div class="box-child"></div>
  </div>
  <div id="boxTwo">
    <div class="box-child"></div>
  </div> -->
</body>
</html>

 

static는 화면에 고정되어 스크롤을 내려도 움직이지 않습니다.

pixed는 스크롤을 내리면 같이 내려옵니다.

absolute는 <div><div>abc</div></div> 부모 div 내에서 영향을 받지 않고 부모 body 태그 내에서 영향을 받습니다.

하지만 부모 div에서 position: relative를 해주면 부모 영역 내에서 css효과를 적용받게 됩니다.

 

자료 출처: 유튜버 nomad coder

 

반응형

'2020 > CSS' 카테고리의 다른 글

CSS Transition  (0) 2020.02.16
css states(hover, active, focus, visited)  (0) 2020.02.16
PSEUDO SELECTOR  (0) 2020.02.16
NTH TEST SITE  (0) 2020.02.16
CSS FLEX PRACTICE  (0) 2020.02.16
블로그 이미지

꽃꽂이하는개발자

,