I need to make a div float inside another div and move on scrolling, but I need the floating div to not pop out of a container div
I need the floating div to stay inside the container div
Any idea how to do this?
body {
height: 800px;
}
#main-container {
width: 100px;
height: 300px;
background-color: black;
margin-top: 100px;
}
#secondary-container {
width: 90px;
height: 30px;
background-color: red;
position: fixed;
}
<body>
<div id="main-container">
<div id="secondary-container"></div>
</div>
</body>