[Support request] Alternating backgrounds on a container within a query loops template & grid

Home Forums Support [Support request] Alternating backgrounds on a container within a query loops template & grid

Home Forums Support Alternating backgrounds on a container within a query loops template & grid

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2394487
    Michael

    pretty straight forward but, I haven’t figured out how to get an alternating background going. basic structure is the query loop, within the post template i have a container > a two column grid > first column container > and a container with in that where im trying to have an alternating background, namely two different linear gradients representing the brands two main colors. This is on a page pointing to a set of posts from a custom post type. I’m able to change the background of a specific instance using the post id in the css, but cant get a ‘nth child’ working on my own. Feel like I’m missing what should be way easier to figure out.

    here’s the code to change an instance of the background, with ‘zoom’ and ‘imgshapes’ being the classnames I have on the container in question in two different queries:

    .zoom, .imgshapes {
    background-image: linear-gradient(135deg, var(–accent), var(–accent-dark) 15%, rgba(0, 0, 0, 0) 15.2%, rgba(0, 0, 0, 0) 84.8%, var(–accent-dark) 85%, var(–accent));
    }
    .post-343695 > .gb-container > .gb-inside-container > .gb-container > .gb-inside-container > .gb-grid-wrapper > .gb-grid-column > .gb-container > .gb-inside-container > .zoom {
    background-image: linear-gradient(135deg, #0059e8, var(–contrast) 15%, rgba(0, 0, 0, 0) 15.2%, rgba(0, 0, 0, 0) 84.8%, var(–contrast) 85%, #0059e8);
    }

    #2394896
    David
    Staff
    Customer Support

    Hi there,

    to use nth-child, you can:

    1. Select the Grid Block inside your Query Loop. Give it a class eg. alternate-backgrounds

    2. Use that class to target the direct descendant gb-grid-column element with nth-child, then the target element. Eg.

    
    .alternate-backgrounds > .gb-grid-column:nth-child(odd) .imgshapes {
        /* your odd post img shapes style */
    }
    
    .alternate-backgrounds > .gb-grid-column:nth-child(even) .imgshapes {
        /* your even post img shapes style */
    }
    #2395981
    Michael

    I really appreciate it. got it working very quickly with that code.

    #2396324
    David
    Staff
    Customer Support

    Awesome – glad to be of help

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