position:sticky doesn't work together with display:flex on IE 11
According to caniuse.com position: sticky is not supported in IE11 and display: flex have partial support because lots of bugs.
I don't have much experience with StickyState but I use StickyBits and it works just fine.
EDIT:
Working example
<div class="flexbox-wrapper">
<div class="regular">
This is the regular box
</div>
<div class="sticky" id="stickyEl">
This is the sticky box
</div>
</div>
stickybits('#stickyEl');
body {
height: 1500px;
}
.flexbox-wrapper {
display: flex;
display: -ms-flexbox;
}
.regular {
background-color: blue;
height: 600px;
-ms-flex: 1 0 auto;
}
.sticky {
position: -webkit-sticky;
position: sticky;
top: 0;
align-self: flex-start;
background-color: red;
}
make a div sticky in IE and in top of footer
Writing some few lines of JavaScript should do the trick for this requirement. We can have the main footer as our indicator if we should have the sub footer position: fixed
or position: relative
based on the current window scroll position - this is what sticky
is after all, i.e., a hybrid of fixed
& relative
.
In my solution below, the general advantage is that the event listener for scroll only kicks in when the client is using IE11. I've found that IE11 actually removes the sticky
position style on the DOM since it does not support it.
In short, moderns browsers are still going to use sticky
and the below code is simply backup when the user is on IE11.
<!-- place the style inline to cater the condition statement -->
<div class="slider" style="position: sticky;">
.slider {
background: #006264;
color: white;
position: fixed; /* fixed is for the IE11 fallback */
bottom: 0px;
width: 100%;
height: 60px;
}
// IE11 actually removes "sticky" from attribute "styles" value. So at this point we can control when to add an event listener (i.e., Modern browsers will still use position: sticky)
if (divFooter.style.position != "sticky") {
window.addEventListener("scroll", function() {
if (mainFooter.getBoundingClientRect().top - window.innerHeight <= 0) {
divFooter.style.position = "relative";
mainFooter.style.marginTop = "0";
} else if (mainFooter.getBoundingClientRect().top - window.innerHeight > 0) {
divFooter.style.position = "fixed";
mainFooter.style.marginTop = divFooter.clientHeight.toString() + "px";
}
})
}
var divFooter = document.querySelector(".slider");
var mainFooter = document.querySelector(".footer");
// IE11 actually removes "sticky" from attribute "styles" value. So at this point we can control when to add an event listener (i.e., Modern browsers will still use position: sticky)
if (divFooter.style.position != "sticky") {
window.addEventListener("scroll", function() {
if (mainFooter.getBoundingClientRect().top - window.innerHeight <= 0) {
divFooter.style.position = "relative";
mainFooter.style.marginTop = "0";
} else if (mainFooter.getBoundingClientRect().top - window.innerHeight > 0) {
divFooter.style.position = "fixed";
mainFooter.style.marginTop = divFooter.clientHeight.toString() + "px";
}
})
}
html,
body {
margin: 0;
}
.placeholder {
border: 1px solid black;
margin: 0 auto;
text-align: center;
height: 300px;
}
.slider {
background: #006264;
color: white;
position: fixed;
bottom: 0px;
width: 100%;
height: 60px;
}
.footer {
background: #04246A;
color: white;
font-weight: bold;
margin: 0 auto;
height: 119px;
}
<div class="main">
<div class="placeholder">This div holds place</div>
<div class="placeholder">This div holds place</div>
<div class="placeholder">This div holds place</div>
<div class="placeholder">This div holds place</div>
<div class="placeholder">This div holds place</div>
<div class="slider" style="position: sticky;">
This is the footer
</div>
</div>
<div class="footer">This is the main footer</div>
Bottom 0 is not working On Internet Explorer 11
I don't know why this worked: I simply set the wildcard(*)'s box sizing to content-box, then set overflow of the button div to hidden. And just like that the issue went away.
position:sticky is not working
It works fine if you move the navbar outside the header. See below. For the reason, according to MDN:
The element is positioned according to the normal flow of the document, and then offset relative to its flow root and containing block based on the values of top, right, bottom, and left.
For the containing block:
The containing block is the ancestor to which the element is relatively positioned
So, when I do not misunderstand, the navbar is positioned at offset 0 within the header as soon as it is scrolled outside the viewport (which, clearly, means, you can't see it anymore).
.navbar { background: hotpink; width: 100%; height: 50px; position: -webkit-sticky; position: sticky; top: 0;}
.header { height: 150px; background: grey;}
body { height: 800px; position: relative;}
<div class="header"><div class="desc">Description</div><div class="logo"><img src=""/></div></div>
<div class="navbar"></div>
Related Topics
How to Append Querystrings to a Url on Submit of a Form
How to Use CSS to Show on Hover Tool-Tips Using the Same Text Which Is Shortend With Ellipses
Angular 2: Get Position of HTML Element
Why Align Items Center Not Working
How to Make Bootstrap 4 Cards the Same Height in Card-Columns
How to Change Bootstrap 4 Drop-Down Colors
Why Is There a White Space Between Parent Div and Inner Div in React
How to Embed Pdf File With Responsive Width
Alternative to Iframes With Html5
How to Make Transparent Color White Instead of Black in Html2Canvas
Pressing Spacebar Scrolls Page Down
Align the Radio Buttons on the Center Whatever the Text Length
How to Set Width of Mat-Table Column in Angular
When Div With Absolute Position Is Added Cannot Click on Links
Absolutely Position One Element Relative to Its Sibling Element
How to Always Show the Vertical Scrollbar in a Browser