-
Anonymous
Hey guys,
I am trying to create the effect of a small LED lighting up when a button is hovered over. You will see the Red, Orange, Yellow and Cream Buttons on the home page. The LED’s are currently Dark Red.
The only way I can think of to make the LED turn Bright Red, is to layer a duplicate image of the button over the top, which has a Bright Red LED. But for this to work, I need the duplicate image to be hidden until hovered over. I guess in simple terms, I need to swap images on hover. Can I do this with GB and if so, how?
If you have a better suggestion than my solution, please feel free to share.
Thanks -
Hi there,
ok, you could add the image as a background to a container and then place an image block inside that container.
For example, create a new draft page and switch the Editor to Code View ( from the editor top bar 3 dot menu ).
Then copy and paste the following code:<!-- wp:generateblocks/container {"uniqueId":"bd515ae1","isDynamic":true,"blockVersion":4,"display":"flex","metadata":{"name":"Flex Row"}} --> <!-- wp:generateblocks/container {"uniqueId":"600560b3","isDynamic":true,"blockVersion":4,"spacing":{"paddingLeft":"20px","paddingRight":"20px"},"borders":{"borderRightWidth":"2px","borderRightStyle":"solid"},"metadata":{"name":"column with padding + border"}} --> <!-- wp:generateblocks/container {"uniqueId":"802beb57","bgImage":{"id":"","image":{"url":"https://dev.carlcox.com/wp-content/uploads/2024/04/Red-808.png","height":58,"width":58,"orientation":"landscape"}},"bgOptions":{"selector":"element","opacity":1,"overlay":false,"position":"center center","size":"contain","repeat":"no-repeat","attachment":""},"isDynamic":true,"blockVersion":4,"sizing":{"width":""},"metadata":{"name":"container has bg"}} --> <!-- wp:generateblocks/image {"uniqueId":"5324b2c2","sizeSlug":"full","blockVersion":2} --> <figure class="gb-block-image gb-block-image-5324b2c2"><img class="gb-image gb-image-5324b2c2" src="https://dev.carlcox.com/wp-content/uploads/2024/04/Red-808.png" alt=""/></figure> <!-- /wp:generateblocks/image --> <!-- /wp:generateblocks/container --> <!-- /wp:generateblocks/container --> <!-- wp:generateblocks/container {"uniqueId":"1101d680","isDynamic":true,"blockVersion":4,"spacing":{"paddingLeft":"20px","paddingRight":"20px"},"borders":{"borderRightWidth":"2px","borderRightStyle":"solid"},"metadata":{"name":"column with padding + border"}} --> <!-- wp:generateblocks/container {"uniqueId":"3745b20c","bgImage":{"id":"","image":{"url":"https://dev.carlcox.com/wp-content/uploads/2024/04/Red-808.png","height":58,"width":58,"orientation":"landscape"}},"bgOptions":{"selector":"element","opacity":1,"overlay":false,"position":"center center","size":"contain","repeat":"no-repeat","attachment":""},"isDynamic":true,"blockVersion":4,"sizing":{"width":""},"metadata":{"name":"container has bg"}} --> <!-- wp:generateblocks/image {"uniqueId":"0cc5b6af","sizeSlug":"full","blockVersion":2} --> <figure class="gb-block-image gb-block-image-0cc5b6af"><img class="gb-image gb-image-0cc5b6af" src="https://dev.carlcox.com/wp-content/uploads/2024/04/Red-808.png" alt=""/></figure> <!-- /wp:generateblocks/image --> <!-- /wp:generateblocks/container --> <!-- /wp:generateblocks/container --> <!-- wp:generateblocks/container {"uniqueId":"ac403cc8","isDynamic":true,"blockVersion":4,"spacing":{"paddingLeft":"20px","paddingRight":"20px"},"borders":{"borderRightWidth":"2px","borderRightStyle":"solid"},"metadata":{"name":"column with padding + border"}} --> <!-- wp:generateblocks/container {"uniqueId":"bc63e243","bgImage":{"id":"","image":{"url":"https://dev.carlcox.com/wp-content/uploads/2024/04/Red-808.png","height":58,"width":58,"orientation":"landscape"}},"bgOptions":{"selector":"element","opacity":1,"overlay":false,"position":"center center","size":"contain","repeat":"no-repeat","attachment":""},"isDynamic":true,"blockVersion":4,"sizing":{"width":""},"metadata":{"name":"container has bg"}} --> <!-- wp:generateblocks/image {"uniqueId":"877df373","sizeSlug":"full","blockVersion":2} --> <figure class="gb-block-image gb-block-image-877df373"><img class="gb-image gb-image-877df373" src="https://dev.carlcox.com/wp-content/uploads/2024/04/Red-808.png" alt=""/></figure> <!-- /wp:generateblocks/image --> <!-- /wp:generateblocks/container --> <!-- /wp:generateblocks/container --> <!-- wp:generateblocks/container {"uniqueId":"c4ffcd27","isDynamic":true,"blockVersion":4,"spacing":{"paddingLeft":"20px","paddingRight":"20px"},"borders":{"borderRightWidth":"","borderRightStyle":""},"metadata":{"name":"column with padding + border"}} --> <!-- wp:generateblocks/container {"uniqueId":"f49af4e4","bgImage":{"id":"","image":{"url":"https://dev.carlcox.com/wp-content/uploads/2024/04/Red-808.png","height":58,"width":58,"orientation":"landscape"}},"bgOptions":{"selector":"element","opacity":1,"overlay":false,"position":"center center","size":"contain","repeat":"no-repeat","attachment":""},"isDynamic":true,"blockVersion":4,"sizing":{"width":""},"metadata":{"name":"container has bg"}} --> <!-- wp:generateblocks/image {"uniqueId":"014ec18a","sizeSlug":"full","blockVersion":2} --> <figure class="gb-block-image gb-block-image-014ec18a"><img class="gb-image gb-image-014ec18a" src="https://dev.carlcox.com/wp-content/uploads/2024/04/Red-808.png" alt=""/></figure> <!-- /wp:generateblocks/image --> <!-- /wp:generateblocks/container --> <!-- /wp:generateblocks/container --> <!-- /wp:generateblocks/container -->
This will provide this layout:
https://app.screencast.com/96f6n6q2lC1Oa
In the Flex Row, there are column containers which has the Padding and the Borders
Inside each of those is another Container that has a background image and contains an image block.The background image and image block in my example are the same image ( off your site ).
Swap the image block image for one with the Bright LED. Making sure its the exact same size as the background image.then it would quite simple to apply an effect to the container with background to hide the Image Block, and then show it on hover. Which we can help with if you want to set it up.
NOTE: You’re current hover effect needs to apply to the container with the background in this setup -
Anonymous
Hey team,
I have added the new images and an Opacity & Blend effect to the background image. This has worked, however for some strange reason it has resized the background image and made it bigger? Other than adding the new images, I have only changed the Opacity & Blend effect settings, yet it is resizing the background image? See /test-lights/I have also added my Captions (Headings) and they have also distorted the images?
I created a clone page under /experiment and replaced my Grid with the new Flex Row layout. As you can see when compare to the Home Page, this has broken the layout and still does not seem to work?
Thanks -
David
Looking at test-lights.
in your child theme you have this CSS:
figure { margin: 1em 40px; }
Which is adding space around the figure which inturn gets added to the size of the parent container hence the larger background image.
1. select the container with the background image:
2. give it a CSS class eg.remove-figure-margins
2.1 add this CSS to remove that margin:.remove-figure-margins figure { margin: 0; }
3. set the Background Images > Position to CENTER TOP
-
Anonymous
Hey David, as you can see on the /experiment page, I have implemented the blocks and the latest fix. Indeed, it has fixed one of the buttons, however the other 3 buttons are missing, as are the border lines?
Thanks -
David
Select each of the column Container Blocks and in Layout set their Z-Index to
1
-
Anonymous
Thanks David.
Its almost there, but the buttons are really big and the border lines, not quite lining up. I’ve set all the Column Containers to 25%, which I though would fix this, but still the buttons are too big. If you look at the home page, you’ll see how they should look and I am trying to use the same settings, but not quite getting it.
Once the /experiment page buttons is correct, I will simply copy that Flex Row container, over to the Home Page.
Thanks
-
David
If you select each of the column container blocks.
For reference:
https://app.screencast.com/96f6n6q2lC1Oa?conversation=WIl34vwuFu5zxDiGggCngzthose being the “columns with padding + border”
And increase their left and right padding.
-
Anonymous
I still cant get this line up nicely and now the captions won’t fit either. In addition, it is not consistent with varying browser sizes now. I know it is not yet responsive and I will deal that, once I can get this to hold its shape in desktop view?
Is there anyway I can do this using the layout on the Home page, which works well other than the lights don’t light up?
Thanks -
David
Try this method on your home page, but you may need to modify your hover effects to suit.
1. Duplicate the Image block you have in the first column, and change the second image to the reburied hover image.
2. select the column Container Block the image is inside and in Advanced > Additional CSS Class(es) add:has-image-hover
3. Add this CSS
.has-image-hover:not(:hover) figure:nth-child(2), .has-image-hover:hover figure:nth-child(1) { display: none; }
-
Anonymous
Wow, that worked perfectly David, thank you. That’s some pretty advanced CSS right there isn’t it. What is figure:nth-child?
Thanks again -
David
nth-child
allows you to select a child element based on its logical order.
For example the HTML looks like this:<div class="has-image-hover"> <figure><img></figure> <figure><img></figure> </div>
The parent selector is
has-image-hover
and it has twofigure
child elements.
So this:.has-image-hover figure:nth-child(2)
Targets the 2nd figure child element inside the
has-image-hover
container.More info here:
https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child -
Anonymous
Makes sense, I will look into that further. Thanks so much David, have a great day.
-
David
You’re welcome and you too
- You must be logged in to reply to this topic.