- This topic has 5 replies, 2 voices, and was last updated 7 years ago by
Tom.
-
AuthorPosts
-
September 30, 2016 at 3:53 pm #230780
Paul
I want to add a span inside the post image section, just after the permalink. This would allow me to add an absolute positioned background image on top of the featured image (for a hover effect). Example:
<div class="post-image"> <a href=“#”><span class=“custom-span”></span><img src=“featured-image.jpg”/></a> </div>
I could add this span to the appropriate section in template-tags.php but I might lose that change when the theme gets updated. So, instead, I was thinking I could remove:
<?php do_action( 'generate_after_entry_header' ); ?>
from content.php inside my child theme, and replace it with the following code from template-tags.php :
<div class="post-image"> <a href="<?php the_permalink();?>" title="<?php the_title(); ?>"><?php the_post_thumbnail( apply_filters( 'generate_page_header_default_size', 'full' ), array('itemprop' => 'image') ); ?></a> </div>
I could then add my custom span just after the permalink in the above code and not have to worry about it being removed in a future update. I have tested this and it did work as I intended it to, but I was wondering if there was a better way to achieve the same result?
Thanks 🙂
September 30, 2016 at 4:28 pm #230789Tom
Lead DeveloperLead DeveloperYou could theoretically use the :before pseudo selector instead of adding a span:
.post-image img:before { content: ''; position: absolute; width: 100%; height: 100%; background-color: rgba( 255,255,255, 0.5 ) }
Let me know if that helps or not 🙂
October 1, 2016 at 7:36 am #230889Paul
Thanks Tom. Although that works to a point, the background image isn’t clickable – which could be confusing for users (since I want them to be able to click anywhere on the post image).
October 1, 2016 at 7:46 am #230892Paul
I think solved this now with:
.post-image a:hover::before{ content: ''; position: absolute; background-image: url(https://geekslife.com/wp-content/uploads/2016/09/m-dot.png); background-repeat: no-repeat; height: 100%; width: 100%; }
October 1, 2016 at 8:43 am #230912Paul
Or maybe not. It doesn’t seem to be possible to center the background image with that method.I realized that I can center the background image by making the post-image position relative 🙂
October 1, 2016 at 9:35 am #230935Tom
Lead DeveloperLead DeveloperAwesome! Thanks for posting the solution that works for you 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.