<div class="main">
<div class="block">
<p><b>Save 20% for 24 Hours ONLY! Use code JOY20</b></p>
</div>
<div class="block2"></div>
<div class="block3"></div>
</div>
.block {
position: sticky;
top: 0;
margin: auto;
background-color: #2e89d5;
text-align: center;
color: #fff;
padding: 5px;
}
.block2 {
background-color: red;
height: 500px;
}
.block3 {
background-color: green;
height: 500px;
}