position
μμ±μ μΉ λ¬Έμ μ μμλ€μ μ΄λ»κ² λ°°μΉν μ§λ₯Ό μ νλ μμ±μ΄λ€.
position
μ ν¬κ² λ€ κ°μ§μ μ’
λ₯κ° μλ€.
position
μμ±μ μ
λ ₯νμ§ μμμ λμ κΈ°λ³Έκ°position:relative
μμ±μ΄ μμ λμ μμΉ)position:relative;
μ체λ‘λ νΉλ³ν μλ―Έκ° μκ³ , λ±ν μ΄λ μμΉλ‘ μ΄λνμ§λ μλλ€.
μμΉλ₯Ό μ΄λμμΌμ£Όλ top, right, bottom, left
νλ‘νΌν°κ° μμ΄μΌ μλμ μμΉμμ μ΄λν μ μλ€.
ππ top, right, bottom, left
λ position
μ΄λΌλ νλ‘νΌν°κ° μμ λλ§ μ μ©λλ νλ‘νΌν°μ΄λ€.
μ¬κΈ°μμ λΆλͺ¨μ 쑰건μ position
μ΄ κΈ°λ³Έκ°(static
)μ΄ μλ relative, fixed, absolute
νλλΌλ μμ΄μΌ νλ€.
absolute
λ λΈλΌμ°μ κ° λ¬Έμμ νλ¦κ³Ό μκ΄μμ΄ left, right, top, bottom
μμ±κ°μ μ΄μ©νμ¬ μμλ₯Ό μμΉμν€λ μμ±κ°μ΄λ€.
μλ μμλ₯Ό μ°Έκ³ νμ¬ μ λλ‘ μ΄ν΄ν΄λ³΄μ.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>repl.it</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<style>
* {
box-sizing: border-box;
}
.input-box {
width: 300px;
position: relative;
}
input {
width: 100%;
border: 1px solid #bbb;
border-radius: 8px;
padding: 10px 12px;
font-size: 14px;
}
img {
position: absolute;
width: 17px;
margin: 0;
}
</style>
</head>
<body>
<div class="input-box">
<input type="text" placeholder="κ²μμ΄ μ
λ ₯"/>
<img src="https://s3.ap-northeast-2.amazonaws.com/cdn.wecode.co.kr/icon/search.png" alt="λ보기"/>
</div>
</body>
</html>
κΈ°μ€μ΄ λλ input-box
μ relative
λ₯Ό μ€¬κ³ ,
μ λμ μΈ μμΉμ μμ΄μΌ νλ( = κ²Ήμ³μΌ νλ ) κ°μ absolute
λ₯Ό 쀬λλ input-box
λ΄λΆκ° μλλΌ μμ κ°μ΄ λ°κΉ₯μͺ½μ μμΉνλ€.
μ¬κΈ°μμ μ°λ¦¬κ° μ μ μλ κ²μ κΌ left, right, top, bottom
μμ±κ°μ μ΄μ©ν΄μΌ μνλ κ³³μ λ°°μΉν μ μλ€λ μ μ΄λ€.
μλ μμλ₯Ό 보μ.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>position:absolute;</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<style>
* {
box-sizing: border-box;
}
.input-box {
width: 300px;
position: relative;
}
input {
width: 100%;
border: 1px solid #bbb;
border-radius: 8px;
padding: 10px 12px;
font-size: 14px;
}
img {
position: absolute;
width: 17px;
top: 10px;
right: 12px;
margin: 0;
}
</style>
</head>
<body>
<div class="input-box">
<input type="text" placeholder="κ²μμ΄ μ
λ ₯"/>
<img src="https://s3.ap-northeast-2.amazonaws.com/cdn.wecode.co.kr/icon/search.png" alt="λ보기"/>
</div>
</body>
</html>
img
μ top:10px, right:12px
μ μ£ΌλκΉ κΈ°μ€μ (input-box)μμ top
λ§νΌ 10px
, μ€λ₯Έμͺ½μΌλ‘λΆν° 12px
λ§νΌ μ΄λν κ²μ λ³Ό μ μλ€.
fixed
λ absolute
μμ±κ°κ³Ό λ§μ°¬κ°μ§λ‘ λ¬Έμμ νλ¦κ³Ό μκ΄μμ΄ μμΉλ₯Ό κ²°μ νλ€.
νμ§λ§ position:relative
μΈ μ μΌ κ°κΉμ΄ λΆλͺ¨ νΉμ μ‘°μ μμκ° μλ λΈλΌμ°μ μ°½μ΄ κΈ°μ€μ΄ λλ€.
λ°λΌμ λΈλΌμ°μ μ°½μ μ΄λλ‘ μ€ν¬λ‘€ νλλΌλ κ³μ κ³ μ λμ΄ νμλκ² λλ€.
μ£Όλ‘ λ΄λΉκ²μ΄μ
λ°λ₯Ό κ³ μ μν€λ μ©λλ‘ μ¬μ©νλ€.
κΈ°μ€μ : λΈλΌμ°μ μΌμͺ½ μ κΌμ§μ
μλ μμλ₯Ό μ°Έκ³ ν΄λ³΄μ.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>repl.it</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<style>
body {
background-color: #eee;
height: 800px;
padding-top: 48px;
}
header {
position: fixed;
left: 0;
right: 0;
top: 0;
height: 48px;
background-color: rgba(45, 45, 45, 0.95);
}
header > img {
position: absolute;
left: 50%;
margin-left: -10px;
}
</style>
</head>
<body>
<header>
<img width="20px" height="48px" src="https://www.apple.com/ac/globalnav/4/en_US/images/globalnav/apple/image_small.svg" alt="μ νλ‘κ³ "/>
</header>
</body>
</html>
μμ absolute
μ λμΌνκ², fixed
μ μμ±μ κ°μ§λ μμμλ left: 0; right: 0; top: 0;
μμ±κ°μ μ΄μ©νμ¬ μμΉμμΌμΌ νλ€.
μ°Έμ‘° >
https://developer.mozilla.org/ko/docs/Web/CSS/position
https://www.youtube.com/watch?v=_uYY1oB8yec