Home › Forums › Support › Alternating backgrounds on a container within a query loops template & grid
- This topic has 3 replies, 2 voices, and was last updated 3 years, 6 months ago by
David.
-
AuthorPosts
-
October 30, 2022 at 4:31 pm #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);
}October 31, 2022 at 3:29 am #2394896David
StaffCustomer SupportHi there,
to use nth-child, you can:
1. Select the Grid Block inside your Query Loop. Give it a class eg.
alternate-backgrounds2. Use that class to target the direct descendant
gb-grid-columnelement 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 */ }October 31, 2022 at 2:24 pm #2395981Michael
I really appreciate it. got it working very quickly with that code.
November 1, 2022 at 1:11 am #2396324David
StaffCustomer SupportAwesome – glad to be of help
-
AuthorPosts
- You must be logged in to reply to this topic.