[Resolved] Offset content when topbar is active

Home Forums Support [Resolved] Offset content when topbar is active

Home Forums Support Offset content when topbar is active

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #803554
    Roger

    Is there a way to offset the first content section on the page when displaying a top bar (in my case, the slider or page hero)?

    I’ve offset the primary navigation, but can’t figure out how to increase the padding so that the hero slot retains the same spacing below the navigation when the top bar is active.

    Thanks for your help.

    #803577
    David
    Staff
    Customer Support

    Hi there,

    not sure if i understand correctly, are you wanting the layout to remain unchanged whether there is a top bar or not?

    #803582
    Roger

    Hi David. What I’m after is if the top bar is displayed, the hero padding is increased by the equivalent amount. Is that possible?

    #803883
    David
    Staff
    Customer Support

    So we could try adding a class to the body when the top bar is hidden, as you already have cookied close top bar script try updating it to this:

    jQuery(document).ready( function( $ ) {
        // Get our cookie
        var cookie = getCookie('closetopbar');
    
        // Check if the cookie is set
        if(cookie){
            // If yes, hide the top bar
            $('.top-bar').hide();
     
            // Add this code below
            $("body").addClass("top-bar-hidden"); 
     
        }else{
            // If no, fire a function when the close button is clicked
            $('.top-close-button').on('click', function(e) {
                e.preventDefault();
    
    					setCookie('closetopbar',true,0);
    					
                $('.top-bar').css('transform', 'translate(0%, -100%)');
     
                // Add this code below
                $("body").addClass("top-bar-hidden"); 
     
                if ($('div#wpadminbar')[0]){
                    $('body').css('transform', 'translate(0, -112px)');
                } else {
                    $('body').css('transform', 'translate(0, -76px)');
                }
            });
        }
    });

    There are two instances of:

    // Add this code below
    $("body").addClass("top-bar-hidden"); 

    Which need to be added – you can change the comment.

    If it works we should see the top-bar-hidden class in body tag.
    We can then do some CSS that uses body:not(.top-bar-hidden) .element { styles }

    #804238
    Roger

    Perfect. Thanks a million, David, that does exactly what I needed! 🙂

    #804240
    David
    Staff
    Customer Support

    Awesome – Glad to be of help.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.