Header Fixed CSS - Transform Translate X

Asked

Viewed 251 times

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');
});

1 answer

1

I had a very similar problem a while back.. First check if the header’s vertical and horizontal positioning (top or bottom, left or right) are defined. This is the main reason for bugs of elements with "Fixed" in the middle of the page.

If this doesn’t work, could you let me know which browser you’re using and which operating system your device is? if possible also send the website URL to facilitate.

  • Is on localhost. The header has the properties top and left defined. 0 and 0 respectively. I am using the Chrome simulator. I have no device in hand.

  • 1

    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?

  • I added my question.

  • 1

    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.

  • I put the header as Children of body and changed to position: absolute. The header was in the top: 0 when I rolled the page. It’s not what I need, I need the header follow the scroll... or this was some debug ?

  • 1

    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>

  • I had already read that question and tested the answers you sent me in the chat. None worked. Strange this.

  • 1

    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!

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.