• Resolved andysb72

    (@andysb72)


    Hi. So I’d like to add a different featured image to all my static pages (I’m using FullWidth-nosidebar) and have the ability to change the image with a hover.

    I’ve tried the solution for adding the featured image from this post but what I’m guessing that I really need is for the image to be the background of a container so I can control the hover in the CSS using page IDs to target each page individually.

    Also it would be great if said images resized responsively with different browser window sizes (like the homepage slider does in the demo.)

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter andysb72

    (@andysb72)

    I’m ALMOST THERE!

    I’ve got the code to put the featured image in as a background image (from this post) with the idea that I could create the HOVER state in the style.css to load a new background image.

    BUT this puts the background image into the resulting page with a STYLE TAG, which I can’t change in the CSS because the style tag trumps the style.css doc.

    Is there anyway to change that?

    Here’s the code

    <?php if (has_post_thumbnail( $post->ID ) ): ?>
    <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
    <div id="custom-bg" style="background-image: url('<?php echo $image[0]; ?>')">
    
    </div>
    <?php endif; ?>

    You can write a rule that overrides inline style by using the !important clause at the end of the property value. In fact, using the !important clause is the only way to override an inline style (unfortunately, many beginning web developers tend to overuse it when it’s not necessary).

    For example, if you want to change the background-image property on hover, you could do something like this:

    .page-id-123 #custom-bg:hover {
       background-image: url('https://example.com/images/new_image.jpg') !important;
    }

    Thread Starter andysb72

    (@andysb72)

    That worked!!

    Thanks so much, Crouching Bruin, for teaching me that!

    Hi @crouchingbruin,

    I hope you are well today and thank you for helping here.

    Your help here is really appreciated.

    Thanks,
    Movin

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add Feature image on static pages with mouseover’ is closed to new replies.