Sticky Positioning
Sticky positioning is like a blend of fixed positioning. The element behaves as if it is relatively positioned until it reaches a point after which it acts as if it is fixed in place.
Code Sample:
<!DOCTYPE html> <html> <head> <style> .sticky-box { position: sticky; top: 0; width: 100%; background-color: lightpink; padding: 10px; border: 1px solid black; } </style> </head> <body> <div class="sticky-box">This box will stick to the top of the page when you scroll.</div> <p style="height: 3000px;">Keep scrolling...</p> </body> </html> |
Sticky Positioning
Sticky positioning is like a blend of fixed positioning. The element behaves as if it is relatively positioned until it reaches a point after which it acts as if it is fixed in place.
Code Sample:
<!DOCTYPE html> <html> <head> <style> .sticky-box { position: sticky; top: 0; width: 100%; background-color: lightpink; padding: 10px; border: 1px solid black; } </style> </head> <body> <div class="sticky-box">This box will stick to the top of the page when you scroll.</div> <p style="height: 3000px;">Keep scrolling...</p> </body> </html> |
Copyrights © 2024 letsupdateskills All rights reserved