Currently i have a sticky div class to display a heading for my site, however when not "sticky" (when the user is currently at the top of the screen) it has a margin to the left and top, which is not desired: Page currently. I am aiming to have a "smooth" transition between the sticky and the browser. This describes what i want nicely.
My code currently:
html,
body {
background-color: white;
}
div.sticky {
/* Sticky bar for */
position: -webkit-sticky;
/* Safari */
position: sticky;
top: 0;
background-color: #6cb0f9;
width: 2000px;
height: 100px;
margin: 0;
text-align: center;
font-family: "Comic Sans MS", "Comic Sans", sans-serif;
font-size: 30px;
}
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<body>
<div class="sticky">This is my sticky div class!</div>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</body>
</html>
Whatever i set "margin" to it does not change the margins on either side, even upon specifying "margin-left" and "margin-top" to 0, placing this element outside of body does not work either. A CSS or HTML solution would be prefered.