How to set featured image size in percentage ?
-
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)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to set featured image size in percentage ?’ is closed to new replies.