3
I’m trying to get the header
from the mobile site stay fixed
onscreen.
However, I have a button on this header
that opens the MENU to the right of the site, using the transform: translateX(-15%)
applied in the main
. When I’m at the top of the site works perfectly.
Now if the site is not at the top, it is in the middle of the screen for example, by clicking the button, the MENU is shown, but the header
some. And I found out it’s because of the transform: translate
in the main
.
That’s a BUG ?
Has a hack to solve this ?
CSS
main#main{
transition: all 0.3s ease;
background-color: #FFF;
&.is-active{
transform: translateX(-210px);
}
}
header#header{
position: fixed;
width: 100%;
background-color: #a7ddb3;
border-bottom: 8px solid #01613c;
height: 50px;
top: 0;
left: 0;
z-index: 3;
}
JS
var clickDeviceEvent = 'touchstart' in window ? 'touchstart' : 'mousedown';
var menuMobile = $("main, .menu-language, body, .open-menu");
urlBase = $('body').data('base');
// Abrir Menu Mobile
$('.open-menu').on(clickDeviceEvent, function(e){
e.preventDefault();
menuMobile.toggleClass('is-active');
});
Is on localhost. The
header
has the propertiestop
andleft
defined. 0 and 0 respectively. I am using the Chrome simulator. I have no device in hand.– Diego Souza
I understand. I don’t know any bug related to Translate, but can i use this described the following Known issues: "Transforms may break position:Fixed Styles of contained Elements" you can see here -> http://caniuse.com/#feat=transforms2d I think it might be related to that. Try positioning with Absolute, just for testing. You could send me the CSS snippet of the header element?
– Rafael Kendrik
I added my question.
– Diego Souza
Great, Place the header element directly on the body, that is, leave the body as the header nodeParent. Change the position from "Fixed" to "Absolute" in the header and tell me if there has been a change.
– Rafael Kendrik
I put the
header
as Children ofbody
and changed toposition: absolute
. Theheader
was in thetop: 0
when I rolled the page. It’s not what I need, I need theheader
follow the scroll... or this was some debug ?– Diego Souza
that, it was just a debug due to Known issues that I quoted above Can I use. " Container elements with position:Fixed associated with Transform in general may have bugs". Another debug you can run is to add a container with postion:Fixed and the header inside with position:relative or initial. ex: <div style="position:Fixed"><header style="position:relative"></header></div>
– Rafael Kendrik
Let’s go continue this discussion in chat.
– Rafael Kendrik
I had already read that question and tested the answers you sent me in the chat. None worked. Strange this.
– Diego Souza
I believe it is a browser bug, as described by can i use -> http://caniuse.com/#feat=transforms2d Known issues 3 and this topic is open here at Stackoverflow -> http://stackoverflow.com/questions/2637058/positions-fixed-doesnt-work-when-using-webkit-transform. I believe it would be best to try an alternative solution! Anyway, I’ll keep looking for a solution, and if you find out I’ll come back and present it to you. Good luck!
– Rafael Kendrik