• So I’m using this code as a part of a query to get related posts

    <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), '' ); ?>
    <div class="relatedpost" style="left:0px; background: url('<?php echo $image[0]; ?>') ;"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    <?php
    endwhile;
        }
    wp_reset_query();
        }
    ?>
    </div>

    This part is supposed to get the featured image url so I can use it as a background for the DIV with class “.relatedpost” . The problem is I need to set the size of the background image to 100% for both height and width. I tried using this css but it didn’t work :

    .relatedpost {
                background-size:100% 100%;
                background-repeat:no-repeat;
        }

    It has no effect at all. So I tried using

    <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail' ); ?>

    and then changed the “thumbnail” style in CSS to this :

    img.attachment-thumbnail {width:100%;height:100%}

    And it didn’t change anything.
    So how can I set the size in percentage relative to the parent element using the part of the query code stated above ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • So, you need this background image to be responsive. can you provide live website url?

    Thread Starter Marow95

    (@marow95)

    No, I just want it to be the background of the related post box.
    And I’m developing the theme on my local host right now so I can’t provide live preview.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to set featured image size in percentage ?’ is closed to new replies.