Front-End/CSS
[CSS] Ex15_position.html
이뮨01
2023. 6. 12. 12:30
요소의 위치를 어떤 기준으로 배치할지를 배우다.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#parent{
width: 200px;
height: 600px;
background-color: gray;
}
.box{
width:200px;
height: 200px;
color: white;
}
.child1{
background-color: #ff4949;
/* relative: 현재 위치를 기준으로 요소를 배치 */
position: relative;
/* top: 0;
left: -20px; */
bottom: 20px;
right: 30px;
}
.child2{
background-color: #f9ca24;
/* absolute: 최상단의 위치를 기준으로 요소를 배치 */
position: absolute;
/* top: 0;
left: 0; */
bottom: 0;;
right: 0px;
}
.child3{
background-color: #0984c3;
}
</style>
</head>
<body>
<div id="parent">
<div class="box child1">Child</div>
<div class="box child2">Child</div>
<div class="box child3">Child</div>
</div>
</html>
결과창을 보고 relative와 absolute를 구별하면 쉽다.