I have read as much as I can cope with about position sticky in css, but it is not behaving the way I expect. Can somebody please explain?
Here is what I have so far:
#upper {
width: 200px;
height: 200px;
background-color: blue;
}
#middle {
width: 200px;
height: 200px;
background-color: yellow;
position: sticky;
left: 100px;
top: 100px;
}
#lower {
width: 200px;
height: 200px;
background-color: red;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>sticky position</title>
<link rel="stylesheet" href="sticky.css">
</head>
<body>
<div id="upper"></div>
<div id="middle"></div>
<div id="lower"></div>
</body>
</html>
What I expect
A blue box top left. An overlapping yellow box (top left of yellow box overlapping bottom right of blue box. A red box below the blue box, with a gap of the size of a box.
What happens
The blue and red boxes are where I expect. The yellow box is shifted to the right as expected, but is not shifted vertically and does not overlap the blue box.
What I have discovered
If I change top:100; to top:300; in the css for middle, the yellow box moves down and overlaps with the red box, as I would expect.