Position absolute, relative, fixed and sticky in CSS
<!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 absolute, relative, fixed and sticky</title>
<link rel="stylesheet" href="CSS/styleEleven.css">
</head>
<body>
<div class="container">
<div class="box" id="box1">1</div>
<div class="box" id="box2">2</div>
<div class="box" id="box3">3</div>
<div class="box" id="box4">4</div>
</div>
</body>
</html>
Below File is styleEleven.css File.
.container {
border: 2px solid #000000;
background-color: #f0e68c;
height: 3444px;
}
.box {
border: 2px solid #ff0000;
width: 150px;
height: 150px;
margin: 2px;
display: inline-block;
}
#box3 {
/* relative: Positions the element relative to its normal position and will leave a gap at its normal position */
/* position: relative; */
/* absolute: Positions the element relative to the position of its first parent */
/* position: absolute; */
/* position: absolute; */
/* top: 34px;
left: 34px; */
/* fixed: Positions the element relative to the browser window */
/* position: fixed;
right: 4px;
bottom: 2px; */
/* sticky: */
position: sticky;
top: 3px;
}
.png)
.png)
.png)
Comments
Post a Comment